简体   繁体   中英

PHP number_format() Function

I am trying to format my number in the following way

12,34,56,789.00

i tried

number_format($row{'money'},2,".",",")

I am getting

123,456,789.00 

This is not what i wanted. So, How to do this?? ( 12,34,56,789.00 )

You can do this just by using the PHP function called money_format

$amount = '123456789.00';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount; // 12,34,56,789.00

The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

So you can use this php code:

setlocale(LC_ALL, ''); // Locale will be different on each system.
$amount = 123456789.00;
$locale = localeconv();
echo number_format($amount, 2, $locale['decimal_point'], $locale['thousands_sep']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM