Method: 1. Use the "*" arithmetic operator to multiply the result of dividing two numbers by 100 to obtain the percentage value of the percentage result. The syntax is "divisor/divisor*100"; 2. Use " ." string connector, just connect the obtained percentage value result with "%", the syntax is "percentage value. "%"".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
In php, clicking "." refers to the string concatenation character, which can combine two or more strings concatenated into a new string.
The specific syntax format is as follows
$string = string1.string2.string3. ······ .stringn;
Divide two beams to obtain the percentage result.
Multiply the result of division by 100 to get the percentage value of the percentage result.
Add a percent sign after the percentage value.
The example is as follows:
<?php $a = 5; $b = 2; $c = $a/$b*100; echo $c . "%"; ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to get the percentage result when dividing two numbers in PHP. For more information, please follow other related articles on the PHP Chinese website!