PHP Math round


round() function: rounds the floating-point number.

grammar:

float round(float val[, int prec])

Returns the result that rounds val according to the specified precision, prec(the number of decimal digits after decimal point). Prec can also be negative or zero(the default).

example:

echo round(3.4); // Output: 3
echo round(3.5); // Output: 4
echo round(1.95583, 2); // Output: 1.96
echo round(11757, -3); // Output: 12000

Tip

PHP default can not correctly handle a similar "12,300.2" string, it should be when the digital processing, a simple way is to use str_replacefunction will be one of the symbols removed.




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook