Home > Backend Development > PHP Problem > 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
Release: 2023-03-15 13:12:02
Original
2862 people have browsed it

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;
Copy after login

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 . "%";
?>
Copy after login

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!

Related labels:
php
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