简体   繁体   中英

Trouble with number_format PHP

I'm having trouble with this line:

print "PRINT for row[EUROS]: " .$row['EUROS'] . "<BR>";
print "PRINT for the format: " .number_format($row['EUROS'], 2, ',', '') ."<BR>";

The number is 24,7 , but it shows me 24.00 . I thought number_format would help me with the , separator, but it doesn't work...

这个错误

Any idea on how to take the decimal values?

use str_replace(',', '.', $row['EUROS']) to replace comma with dot and then use number_format . Cheers!

The third parameter in number_format is the dec_point wich separates decimal point in the output string but not in the input.

"24,7" is not a number, it's a string with a comma in it, which is not a well formed number . The best meaning PHP can extract from that is 24 , with the rest being garbage.

Don't have numbers with commas in them.

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