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? Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/ 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. Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437122 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. ??? Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437127 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 Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437181 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 Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437200 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 Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437203 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. Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437205 Share on other sites More sharing options...
thomashw Posted January 12, 2008 Author Share Posted January 12, 2008 Thanks guys. Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437325 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Mark as solved please Link to comment https://forums.phpfreaks.com/topic/85654-solved-number_format/#findComment-437326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.