mindapolis Posted November 30, 2011 Share Posted November 30, 2011 hi, I have a function that calculates sales tax and it should put 2 numbers after the decimal point but it 's putting 5 numbers after the decimal point. Can someone help me figure out why? function TotalSalesTax($price) { $salesTax = .07; $TotalSalesTax = $price * $salesTax; number_format($TotalSalesTax, 2); return $TotalSalesTax; } Quote Link to comment https://forums.phpfreaks.com/topic/252085-number-format-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2011 Share Posted November 30, 2011 number_format returns the formated string. You are not using the value that number_format returns. Your function is returning the original value that is still in $TotalSalesTax. Quote Link to comment https://forums.phpfreaks.com/topic/252085-number-format-problem/#findComment-1292450 Share on other sites More sharing options...
mindapolis Posted November 30, 2011 Author Share Posted November 30, 2011 I'm not quitefollowing you. It 's returning $TotalSalesTax Quote Link to comment https://forums.phpfreaks.com/topic/252085-number-format-problem/#findComment-1292454 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2011 Share Posted November 30, 2011 The light-blue number_format text are links to the php manual section for that function. I recommend that you look at the example code at that link. Quote Link to comment https://forums.phpfreaks.com/topic/252085-number-format-problem/#findComment-1292455 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.