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

How to convert decimal to percent sign in php

藏色散人
Release: 2023-03-12 20:22:01
Original
2543 people have browsed it

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

php decimal conversion percentage function:

function xx($n) 
{ 
return $n*100.&#39;%&#39;; 
}
Copy after login

If there are requirements for the number of digits in novels

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

Round first, then convert

$str=round(5.055, 2); // 5.06 
$str1=$str."%"; //5.06%
Copy after login

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!

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