Home  >  Article  >  Backend Development  >  Rounding in php_PHP tutorial

Rounding in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:01753browse

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 Specifies the precision (number of decimal digits after the decimal point) for rounding results. 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)."%";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445159.htmlTechArticleFor example, I have 0.10456, should it become 10.5%? round (PHP 3, PHP 4) round -- round floating point numbers Description float round ( float val [, int precision]) Returns val according to the specified precision...
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