Home  >  Article  >  Backend Development  >  How to convert percentage to decimal in php

How to convert percentage to decimal in php

藏色散人
藏色散人Original
2020-09-04 10:28:502487browse

How to convert percentage to decimal in php: First create a PHP sample file; then define a percentage; then convert the percentage to decimal through the "(float)$a/100;" method; finally output the converted value through echo of decimals is enough.

How to convert percentage to decimal in php

Recommended: "PHP Video Tutorial"

PHP percentage to decimal, php decimal conversion percentage function A Xing Xiao Stack

PHP percent to decimal:

$a = "20.544545%";
echo (float)$a/100;

Result: 0.20544545

php Decimal to percent conversion function:

No digits required:

$n*100.'%';

If there are requirements for the number of novels

(1) You can use sprintf(" .2f", $n*100). '%';

(2) Round first, then convert

$str=round(5.055, 2); // 5.06 
$str1=$str."%"; //5.06%

To use the rounding function round()

Example:

  $hhl=round(($hh/$totalpj)*100).’%';//好评率
  $lhl=round(($lh/$totalpj)*100).’%';//良好率
  $ybl=round(($yb/$totalpj)*100).’%';//一般率
  $cl=round(($c/$totalpj)*100).’%';//差率
  $hcl=round(($hc/$totalpj)*100).’%';//很差率

The above is the detailed content of How to convert percentage to decimal in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn