简体   繁体   English

PHP的number_format问题

[英]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 . 这个数字是24,7 ,但显示24.00 I thought number_format would help me with the , separator, but it doesn't work... 我以为number_format可以帮助我使用分隔符,但是它不起作用...

这个错误

Any idea on how to take the decimal values? 关于如何采用十进制值的任何想法?

use str_replace(',', '.', $row['EUROS']) to replace comma with dot and then use number_format . 使用str_replace(',', '.', $row['EUROS'])用点替换逗号,然后使用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. number_format中的第三个参数是dec_point,该点将输出字符串中的小数点分隔开,但不分隔输入中的小数点。

"24,7" is not a number, it's a string with a comma in it, which is not a well formed number . "24,7"不是数字,它是一个带有逗号的字符串,它不是格式正确的数字 The best meaning PHP can extract from that is 24 , with the rest being garbage. PHP可以从中提取的最佳含义是24 ,其余的则是垃圾。

Don't have numbers with commas in them. 请勿包含带逗号的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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