views:

202

answers:

3

Hello,

How to convert percent value to decimal value in PHP to be used in a computation?

Example: 6.15% = .0615

Thanks!

+3  A: 
$dec = $pct / 100;

// if you actually have a % sign in $pct strip it out
$pct = '15%';
$dec = str_replace('%', '', $pct) / 100;
Rob
+1  A: 
function percentToDecimal($percent)
{
    $percent = str_replace('%', '', $percent);
    return $percent / 100;
}
ryeguy
+2  A: 
echo floatval("6.15%") / 100;
Pentium10