Rounding in php

高洛峰
Release: 2023-03-02 20:06:02
Original
1154 people have browsed it

For example, I have 0.10456, do I want it to become 10.5%?

round
(PHP 3, PHP 4)
round -- Round floating point numbers
Explanation
float round (float val [, int precision])
Returns val according to the specified precision precision (the number of digits after the decimal point) The result is rounded. precision can also be negative or zero (default).
Note
PHP cannot handle strings like "12,300.2" correctly by default. See Convert String to Numeric.

echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2 ); // 1.96
echo round(1241757, -3); // 1242000

Note: The precision parameter is only available in PHP 4.

echo round(0.10456*100,1);

$num = 0.10456;
echo round(($num*100),1)."%";
?>

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