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; } Quote 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); //... ?> Quote 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); // Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/262456-2-decimal-places/#findComment-1345070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.