doubledee Posted June 14, 2012 Share Posted June 14, 2012 What is the shortest way/function to convert "1250" to "1,250"? I'm looking at this, which seems very verbose?! number_format ($aboutMeLength, 0, '.', ',' ); Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/ Share on other sites More sharing options...
requinix Posted June 14, 2012 Share Posted June 14, 2012 Putting aside the fact that you could simply use the default values for those last two arguments, It's one statement. How much shorter do you want? Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1353987 Share on other sites More sharing options...
doubledee Posted June 14, 2012 Author Share Posted June 14, 2012 Putting aside the fact that you could simply use the default values for those last two arguments, It's one statement. How much shorter do you want? So is this valid... number_format ($aboutMeLength, ',' ); Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1353988 Share on other sites More sharing options...
requinix Posted June 14, 2012 Share Posted June 14, 2012 What does the manual page say? Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1353990 Share on other sites More sharing options...
jcbones Posted June 14, 2012 Share Posted June 14, 2012 No, number_format accepts 1, 2, or 4 parameters, not 3. With those parameters, the first is the number being passed to the function, the second is the amount of decimal places to show, and the 3rd and fourth is for the separators (decimal, and thousands -> in that order). Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1353991 Share on other sites More sharing options...
doubledee Posted June 14, 2012 Author Share Posted June 14, 2012 What does the manual page say? I wasn't sure if you had to type out the defaults... Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1353993 Share on other sites More sharing options...
Mahngiel Posted June 14, 2012 Share Posted June 14, 2012 What does the manual page say? I wasn't sure if you had to type out the defaults... The defaults for which geographic region??? Brits and such use inverted symbols than the U.S. Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1354000 Share on other sites More sharing options...
scootstah Posted June 15, 2012 Share Posted June 15, 2012 What does the manual page say? I wasn't sure if you had to type out the defaults... Here's a hint: when an argument is in square brackets in the function definition it means that argument is optional, and the value shown in the manual is the default if you do not supply that argument. string number_format ( float $number [, int $decimals = 0 ] ) Therefore you only need to use the first parameter if you want to keep the defaults. Quote Link to comment https://forums.phpfreaks.com/topic/264203-formatting-number-with-commas/#findComment-1354009 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.