How to convert percent value to decimal value in PHP to be used in a computation?
Example: 6.15% = .0615
The % is a percent sign, meaning divided by 100. So 25% means 25/100, or 1/4. To convert a percentage to a decimal, divide by 100. So 25% is 25/100, or 0.25.
11 percent = 0.11 decimal.
Parameter Values Specifies a constant to specify the rounding mode: PHP_ROUND_HALF_UP - Default. Rounds number up to precision decimal, when it is half way there. Rounds 1.5 to 2 and -1.5 to -2.
To turn a percent into an integer or decimal number, simply divide by 100. That is the same as moving the decimal point two places to the left.
$dec = $pct / 100.00;
// if you actually have a % sign in $pct strip it out
$pct = '15%';
$dec = str_replace('%', '', $pct) / 100.00;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With