Home > Backend Development > PHP Tutorial > PHP conversion code between percentage and decimal

PHP conversion code between percentage and decimal

不言
Release: 2023-04-03 13:42:01
Original
4030 people have browsed it

This article introduces to you the content of the article about the mutual conversion code between PHP percentage and decimal. It has a good reference value and I hope it can help friends in need.

PHP Percent to decimal conversion:

 = "20.544545%" ()/100;
结果:0.20544545
Copy after login

php Decimal to percent conversion function:

没有位数要求:

$n*100.'%';
如果有小说位数有要求 

 (1)可以用 sprintf("%01.2f", $n*100).'%'; 
  (2)先 四舍五入,后转换 
    $str=round(5.055, 2); // 5.06 
    $str1=$str."%"; //5.06% 
要用到四舍五入函数round()
  示例:
  $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

Related recommendations:

php paging and regular verification code implementation

Summary of functions to find array difference/intersection in php

The above is the detailed content of PHP conversion code between percentage and decimal. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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