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

How to convert percentage to decimal in php

藏色散人
藏色散人Original
2020-09-12 09:53:302837browse

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

How to convert percentage to decimal in php

Recommended: "PHP Video Tutorial"

PHP percentage to decimal, php decimal conversion percentage function

PHP Percent to decimal:

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

Result: 0.20544545

php Decimal to percent conversion function:

There is no digit requirement:

$n*100.'%';

If there is a novel, there is a digit requirement

(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