jakebur01 Posted October 17, 2009 Share Posted October 17, 2009 I have comma screwing up my shipping calculation. I have been trying to replace the comma with nothing but I am still having trouble. function calculate_shipping_cost() { // as we are shipping products all over the world // via teleportation, shipping is fixed // return 20.00; $base = $_SESSION['weight']; //$base = 12; // $base=str_replace(',','',$base); $multiply = $base*1.1; // $multiply=str_replace(',','',$multiply); $final = $multiply+8; // $final=str_replace(',','',$final); return $final; } function display_shipping($shipping) { // display table row with shipping cost and total price including shipping $_SESSION['shipping']=number_format($shipping, 2); $_SESSION['complete_order']=number_format($shipping+$_SESSION['total_price'], 2); ?> <table border = 0 width = '100%' cellspacing = 0> <tr><td align = 'left'>Shipping</td> <td align = 'right'> <?php echo number_format($shipping, 2); ?></td></tr> <tr><th bgcolor='#cccccc' align = 'left'>TOTAL INCLUDING SHIPPING</th> <th bgcolor='#cccccc' align = 'right'>$<?php echo number_format($shipping+$_SESSION['total_price'], 2); ?></th> </tr> </table><br /> <?php } if(!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); $_SESSION['items'] = 0; $_SESSION['total_price'] ='0.00'; $_SESSION['weight'] = 0; } if(isset($_SESSION['cart'][$new])) $_SESSION['cart'][$new]++; else $_SESSION['cart'][$new] = 1; $_SESSION['total_price'] = calculate_price($_SESSION['cart']); $_SESSION['items'] = calculate_items($_SESSION['cart']); $_SESSION['weight'] = calculate_weight($_SESSION['cart']); } if(isset($_POST['save'])) { foreach ($_SESSION['cart'] as $isbn => $qty) { if($_POST[$isbn]=='0') unset($_SESSION['cart'][$isbn]); else $_SESSION['cart'][$isbn] = $_POST[$isbn]; } $_SESSION['total_price'] = calculate_price($_SESSION['cart']); $_SESSION['items'] = calculate_items($_SESSION['cart']); $_SESSION['weight'] = calculate_weight($_SESSION['cart']); } Link to comment https://forums.phpfreaks.com/topic/177996-solved-trouble-with-comma/ Share on other sites More sharing options...
jakebur01 Posted October 17, 2009 Author Share Posted October 17, 2009 if I echo calculate_shipping_costs() using a weight of 999, the function will return 9 for some reason. Link to comment https://forums.phpfreaks.com/topic/177996-solved-trouble-with-comma/#findComment-938489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.