使用 php 从数字中删除句点后保留零

Keep zeros after removing a period from a number using php

当我使用 PHP str_replace 删除字符串中的句点时,它也会删除字符串后面的零,例如

100.00

转为

100

但我想要

10000

下面是我的代码

function remove_periods($string){
    $string = str_replace('.', '', $string);

    return $string;
}

好吧,有几种方法可以调整您的代码。

这里只有一个:(Demo)

function remove_periods($float){
    return $float * 100;
}

echo remove_periods((float)100.00); // 10000
echo remove_periods((string)100.00); // 10000

还有一个:

function remove_periods($float){
    return number_format($float, 2, '', '');
}