Home >Backend Development >PHP Problem >How to convert decimal point to percentage in php

How to convert decimal point to percentage in php

青灯夜游
青灯夜游Original
2022-04-28 20:51:013044browse

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>";
?>

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!

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