在PHP中将百分比值转换为十进制值

时间:2010-03-05 18:58:38

标签: php decimal

如何在PHP中将百分比值转换为十进制值以用于计算?

示例:6.15%=。0615

3 个答案:

答案 0 :(得分:16)

$dec = $pct / 100;

// if you actually have a % sign in $pct strip it out
$pct = '15%';
$dec = str_replace('%', '', $pct) / 100;

答案 1 :(得分:8)

echo floatval("6.15%") / 100;

答案 2 :(得分:1)

function percentToDecimal($percent)
{
    $percent = str_replace('%', '', $percent);
    return $percent / 100;
}