Php 带str_替换的数字格式

Php 带str_替换的数字格式,php,Php,我需要格式化我的货币值以删除点和逗号,并在非美分值中增加00,这是最好的方法吗 str_replace(['.',','],'', number_format('67.50',2)); return 6750 str_replace(['.',','],'', number_format('112.35',2)); return 11235 str_replace(['.',','],'', number_format('1001',2)); return 100100 直接使用PHP的B

我需要格式化我的货币值以删除点和逗号,并在非美分值中增加00,这是最好的方法吗

str_replace(['.',','],'', number_format('67.50',2)); return 6750 
str_replace(['.',','],'', number_format('112.35',2)); return 11235 
str_replace(['.',','],'', number_format('1001',2)); return 100100

直接使用PHP的BCMath扩展

源代码:

<?php
$num = bcmul('123.45', 100);
var_dump($num);

$num = bcmul('123.456', 100);
var_dump($num);

// The thrid parameter is used to set the number of digits after the decimal place in the result.
$num = bcmul('123.456', 100, 1);
var_dump($num);

$num = bcmul('123456.78', 100);
var_dump($num);

有关更多信息,请参见

我不明白你的问题。为什么1001等于100100?@Wimanicesir它应该是1001.00,格式是2位小数。既然您已经有了可用的值,很可能是一个
双精度
值,为什么不直接使用
$var*100?为什么要通过
number\u format()
str\u replace()绕行?请阅读。无需
str\u replace()
任何东西。@axiac谢谢!我在文档中跳过了这一点,但我使用了数字格式($number,2,,“”)
string(5) "12345"
string(5) "12345"
string(7) "12345.6"
string(8) "12345678"