thomashw Posted January 12, 2008 Share Posted January 12, 2008 I have to variables multiplying together. When I use number_format($variable1 * variable2, 2) and the output is lower than 1000 it works perfectly, but when it's greater than 1000 it stops working properly. If the output was 4763, it outputs 4.00. Any ideas why this happens? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 http://us.php.net/manual/en/function.number-format.php Read the description part. Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 12, 2008 Author Share Posted January 12, 2008 I'm not seeing anything that applies to my question - maybe I'm missing something. ??? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 12, 2008 Share Posted January 12, 2008 The statement you posted (except got the missing "$") should work fine <?php $variable1 = 99; $variable2 = 98; echo number_format($variable1 * $variable2, 2); // --> 9,702.00 ?> However this will fail <?php $variable1 = 9999; $variable2 = 1; echo number_format($variable1,2) * $variable2; // --> 9 ?> the numeric value of 9,999 is 9 as "," is a non-numeric character Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted January 12, 2008 Share Posted January 12, 2008 you're best to get the final result, and then echo the result with the number formatting: <?php $variable1 = 99; $variable2 = 98; $result = $variable1 * $variable2; echo number_format($result); // now you have no problems ?> Regards ACE Quote Link to comment Share on other sites More sharing options...
Barand Posted January 12, 2008 Share Posted January 12, 2008 you're best to get the final result, and then echo the result with the number formatting: Oh!. I thought that was what this did echo number_format($variable1 * $variable2, 2); // --> 9,702.00 Quote Link to comment Share on other sites More sharing options...
twostars Posted January 12, 2008 Share Posted January 12, 2008 you're best to get the final result, and then echo the result with the number formatting: Oh!. I thought that was what this did echo number_format($variable1 * $variable2, 2); // --> 9,702.00 That's right, it works its way from the middle out, not out in. So first, it gets the value of ($variable1 * $variable2), then it performs the number_format function on it which will, as stated, return 9,702.00. Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 12, 2008 Author Share Posted January 12, 2008 Thanks guys. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Mark as solved please Quote Link to comment 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.