round () and concluded that the difference between the floor () ceil (). Rounded, several decimal places, rounding the minimum and maximum rounding

PHP has rounded floating-point, decimal places few, the minimum and maximum rounding rounding operation function, with a corresponding function round (), floor (), ceil (). Understand the basic functions of the application, in order to better flexible application to work, the following description of each function and examples.
round (): rounding floating point numbers can be set to retain several decimal places, the default is zero.
floor (): returns is not larger than the given number to the nearest integer, discarding the fractional part is rounded.
ceil (): returns the number is not less than a given next integer.

Floating point rounding:
round (1.4):. 1
round (for 1.5): 2
round (1.6): 2

Take two decimal floating-point numbers:
round (1.23454,2): 1.23
round (1.04234,2): 1.04
round (1.04534,2): 1.05

It is negative decimal places, such as -2, then the first decimal 0 to 2, and the rounded calculation.
round (1,213,232, -2): 1.2132 million
round (1213252, -2): 1.2133 million

The minimum floating rounded (rounded to small)
Floor (1.3):. 1
Floor (1.99):. 1
Floor (-1.3): -2
Floor (-1.99): -2

Rounded floating point maximum (rounded to large)
ceil (1.0):. 1
ceil (1.0001): 2
ceil (1.99): 2
ceil (-1.3): -1

 

Guess you like

Origin blog.csdn.net/uvyoaa/article/details/83029377