How to convert decimal point to percentage in php

青灯夜游
Release: 2023-03-15 21:28:02
Original
3002 people have browsed it

How to convert decimal point to percentage in php: 1. Use the "*" operator to multiply the decimal by 100, and the syntax "decimal * 100" can convert the decimal into a percentage; 2. Use a string The splicing character "." can splice the percentage value and the "%" character together to form a percentage string. The syntax is "percent value."%"".

How to convert decimal point to percentage in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

If you want to convert the decimal point to a percentage, we first You need to understand the composition of percentages, for example: 20% (0.2), 30% (0.3), 102% (1.02)

The percentage value can be divided into two parts: the percentage value and "%" character; and the percentage value can be obtained by multiplying the decimal by 100.

Therefore, PHP can convert the decimal point into a percentage as follows:

  • Use the "*" operator to multiply the decimal by 100 to get the percentage value

  • Use the string splicing character "." to splice the percentage value and the "%" character together

Implementation example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
echo (0.2*100)."%"."<br>";
echo (0.3*100)."%"."<br>";
echo (0.4*100)."%"."<br>";
echo (0.5*100)."%"."<br>";
echo (1.02*100)."%"."<br>";
?>
Copy after login

How to convert decimal point to percentage in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert decimal point to percentage 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