Home >Backend Development >PHP Problem >How to convert decimal point to percentage in php
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."%"".
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('content-type:text/html;charset=utf-8'); 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>"; ?>
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!