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; } 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/252085-number-format-problem/#findComment-1292455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.