jericho
08-11-2003, 08:37 AM
When I print a variable it appears on my screen like this 832873673. How can I format the variable, so I see it on my screen as: 832 873 673? (thousand seperator)
|
Click to See Complete Forum and Search --> : formatting numbers jericho 08-11-2003, 08:37 AM When I print a variable it appears on my screen like this 832873673. How can I format the variable, so I see it on my screen as: 832 873 673? (thousand seperator) pyro 08-11-2003, 10:54 AM Use chunk_split() (http://us2.php.net/manual/en/function.chunk-split.php) <?PHP $var = "832873673"; $output = chunk_split($var,"3"); echo $output; ?> Da Warriah 08-11-2003, 06:18 PM actually according to the php.net chunk_split() function you posted, that would give: 832 873 673 because the string end defaults to \r\n $output = chunk_split($var,"3", " "); that would do what you wanted;) pyro 08-11-2003, 10:15 PM Nope, it will return exactly what they asked for... jericho 08-12-2003, 03:11 AM Thanks. I applied pyro's original code, but it doesn't do the trick. I have a number 10000 and after echo chunk_split($variable,"3"); I got 100 00. Not good. The space should be counted "from the other side". How to format it right? Kr|Z 08-12-2003, 04:34 AM $var = 10000; $number = number_format($var, " ", " ", " "); jericho 08-12-2003, 05:51 AM Thanks! This works just as it should! jericho 08-12-2003, 06:00 PM OK, how about when I use float(12,2) number? How can I format it so it looks like this: 1 000 000.00? When I apply $number = number_format($var, " ", " ", " "); the 2 decimal numbers are cut off. DaiWelsh 08-13-2003, 05:53 AM Check the documentation for the function here (http://uk.php.net/manual/en/function.number-format.php) . The format you want is probably number_format($var,2,'.',' ') btw, the original suggestion given was not strictly correct as param 2 should be an int. HTH, Dai jericho 08-13-2003, 08:44 AM Thanks! That's correct. DaiWelsh 08-13-2003, 11:26 AM np :) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |