Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Several examples of decimal rounding in java
Several examples of decimal rounding in java
(Learn Baidu! )

Math class provides three methods related to rounding:

The first one: the ceiling

The ceiling means: the ceiling means; This method means that the value of Math.ceil( 1 1.3) is12; Math.ceil.(- 1 1.6) The result is-11;

The second is: the floor.

First of all, his English means floor, and this method means rounding.

Math.floor( 1 1.6) results in11; ?

math . floor(- 1 1.4); The result is-12.

The third one is: circle.

He means rounding, and the algorithm is math.floor (x+0.5); That is, add 0.5 to the original number and then round it down; ?

math . round( 1 1.5); That is, math.floor (11.5+0.5) = math.floor (12) =12; ?

Similarly: math.round (-11.5) = math.floor (-11.5) = math.floor (-1.0).

Original address: network link