Re: Formatting Decimals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Testing this out a little:

mattias@mumin:~$ php -r 'echo "\$".number_format(0.109, 2, ".", ",")."\n";'
$0.11
mattias@mumin:~$ php -r 'echo "$".number_format(0.109, 2, ".", ",")."\n";'
$0.11
mattias@mumin:~$ php -r 'echo "$".number_format("0.109", 2, ".", ",")."\n";'
$0.11

I think the $ should be escaped with a backslash when enclosed within double quotes, but even the second and third tries return the correct result for me. Using PHP 5.2.10.

Cheers,

Mattias

Rick Dwyer wrote:
Hello List.

Probably an easy question, but I am not able to format a number to round up from 3 numbers after the decimal to just 2.

My code looks like this:

$newprice = "$".number_format($old_price, 2, ".", ",");

and this returns "$0.109" when I am looking for "$0.11".


I tried:

$newprice = "$".round(number_format($old_price, 2, ".", ","),2);
But no luck.

Any help is appreciated.

Thanks,

 --Rick





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux