3 回答
TA贡献1836条经验 获得超13个赞
使用str_replace()去除点并不过分。
$string_number = '1.512.523,55';
// NOTE: You don't really have to use floatval() here, it's just to prove that it's a legitimate float value.
$number = floatval(str_replace(',', '.', str_replace('.', '', $string_number)));
// At this point, $number is a "natural" float.
print $number;
几乎可以肯定,这是执行此操作所需的CPU最少的方法,而且很有可能即使您使用一些高级功能也可以做到这一点。
TA贡献1824条经验 获得超6个赞
此功能适用于点或逗号为小数的数字
function floatvalue($val){
$val = str_replace(",",".",$val);
$val = preg_replace('/\.(?=.*\.)/', '', $val);
return floatval($val);
}
$number = "1.325.125,54";
echo floatvalue($number); // The output is 1325125.54
$number = "1,325,125.54";
echo floatvalue($number); // The output is 1325125.54
- 3 回答
- 0 关注
- 568 浏览
添加回答
举报