Home >Backend Development >PHP Problem >How to convert decimal to percent sign in php
How to convert decimals to percent signs in php: 1. Create a PHP sample file; 2. Round the decimals through "round(5.055, 2);"; 3. Through "$str."%" ;" method to convert decimals into percentages.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
php How to convert decimal to percent sign?
PHP percent sign to decimal, php decimal conversion percentage function
PHP percent sign to decimal conversion:
<?php $a = "20.544545%"; echo (float)$a/100; ?>
php decimal conversion percentage function:
function xx($n) { return $n*100.'%'; }
If there are requirements for the number of digits in novels
sprintf("%01.2f", $n*100).'%';
Round first, then convert
$str=round(5.055, 2); // 5.06 $str1=$str."%"; //5.06%
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert decimal to percent sign in php. For more information, please follow other related articles on the PHP Chinese website!