Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert percent value to decimal value in PHP

Tags:

php

decimal

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

Example: 6.15% = .0615

like image 749
steamboy Avatar asked Mar 05 '10 18:03

steamboy


People also ask

How do u convert percents to decimals?

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.

What is 11 percent as a decimal?

11 percent = 0.11 decimal.

How do I round to 2 decimal places in PHP?

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.

How do you turn a percentage into a whole number?

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.


1 Answers

$dec = $pct / 100.00;

// if you actually have a % sign in $pct strip it out
$pct = '15%';
$dec = str_replace('%', '', $pct) / 100.00;
like image 54
Rob Avatar answered Sep 23 '22 02:09

Rob