Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Using number_format without changing decimal
September 12, 2005, 1:36 am
rate this thread
So, I'm running data through an array, and having a little difficulty
in using the number_format function. You see, I'm trying to get a
comma to appear for the thousandths place, however, whenever i use the
number_format function, it also forces rounding of the decimal.
Does anyone know how I can place commas in the thousandths place
WITHOUT doing any decimal rounding? I have some datapoints with two
decimal places, some with four, and others with none. I don't want to
have the function affect any of these decimal places.
- Alexey Kulentsov
September 12, 2005, 7:42 am
Re: Using number_format without changing decimal
This is a bit gruesome but it's the first thing that came to mind:
if ($point = strrpos($num, '.'))
return number_format($num, strlen($num) - $point - 1);
$nums = array(1000.2, 2000.34, 5000.678, 9000);
foreach ($nums as $num)
print $num . ' -> ' .number_format_keep_decimals($num);
Andy Hassall :: email@example.com :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool