How to convert percentage to decimal in php

藏色散人
Release: 2023-03-05 21:12:01
Original
2830 people have browsed it

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;
Copy after login

Result: 0.20544545

php Decimal to percent conversion function:

There is no digit requirement:

$n*100.'%';
Copy after login

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%
Copy after login

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).’%';//很差率
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template