jester626 Posted January 13, 2008 Share Posted January 13, 2008 When running a total number of records in a database the results display as "4567" how would I tell the script to add a comma for thousands, millions, etc (ie. 4,567 or 1,234,567) Thanks Link to comment https://forums.phpfreaks.com/topic/85812-how-to-add-comma-in-numbers-solved/ Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 Try: $n = 1234567.8901; $num = number_format($n, 2, '.', ''); print $num."<br>"; Link to comment https://forums.phpfreaks.com/topic/85812-how-to-add-comma-in-numbers-solved/#findComment-437942 Share on other sites More sharing options...
jester626 Posted January 13, 2008 Author Share Posted January 13, 2008 That code adds decimal points not the commas. Thanks Link to comment https://forums.phpfreaks.com/topic/85812-how-to-add-comma-in-numbers-solved/#findComment-437944 Share on other sites More sharing options...
jester626 Posted January 13, 2008 Author Share Posted January 13, 2008 Solved it, Here is what I came up with $n = 12345 echo $english_format_number = number_format($n); This will display 12,345 Hope this is of some help to others Link to comment https://forums.phpfreaks.com/topic/85812-how-to-add-comma-in-numbers-solved/#findComment-437946 Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 Your right you know! Wasn't looking, here's two way's: $n = 12345.67890; $num = number_format($n); print $num." (notice how it's rounded up!)<br><br>"; $num = number_format($n, 2, '.', ','); print $num."<br>"; The second is same as before but with the missing char! Well you've actually solved it! Link to comment https://forums.phpfreaks.com/topic/85812-how-to-add-comma-in-numbers-solved/#findComment-437947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.