Home  >  Article  >  Backend Development  >  How to get the percentage result when dividing two numbers in PHP

How to get the percentage result when dividing two numbers in PHP

WBOY
WBOYOriginal
2022-02-22 14:12:562814browse

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. "%"".

How to get the percentage result when dividing two numbers in PHP

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

How to get the percentage result when dividing two numbers in php

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:

How to get the percentage result when dividing two numbers in PHP

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!

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