mindapolis Posted May 12, 2012 Share Posted May 12, 2012 Hi, I'm trying to force 2 decimal places with the following function but it 's not working. Any suggestions? function ShippingCost() { $shippingCost = 4.00; number_format($shippingCost,2); return $shippingCost; } Link to comment https://forums.phpfreaks.com/topic/262456-2-decimal-places/ Share on other sites More sharing options...
cyberRobot Posted May 12, 2012 Share Posted May 12, 2012 You need to assign the result of number_format() back into the variable. <?php //... $shippingCost = number_format($shippingCost,2); //... ?> Link to comment https://forums.phpfreaks.com/topic/262456-2-decimal-places/#findComment-1345018 Share on other sites More sharing options...
noXstyle Posted May 12, 2012 Share Posted May 12, 2012 You need to assign the result of number_format() back into the variable. True. Or you could just return the output of the number_format: // return number_format($shippingCost,2); // Link to comment https://forums.phpfreaks.com/topic/262456-2-decimal-places/#findComment-1345029 Share on other sites More sharing options...
mindapolis Posted May 13, 2012 Author Share Posted May 13, 2012 that worked. thank you so much Link to comment https://forums.phpfreaks.com/topic/262456-2-decimal-places/#findComment-1345070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.