Home  >  Article  >  Backend Development  >  How to convert decimal to percent sign in php

How to convert decimal to percent sign in php

藏色散人
藏色散人Original
2021-09-22 10:32:252521browse

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.

How to convert decimal to percent sign in php

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.&#39;%&#39;; 
}

If there are requirements for the number of digits in novels

sprintf("%01.2f", $n*100).&#39;%&#39;;

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!

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