Here are a few ways to round decimal values to integers: Math.ceil (), Math.floor (), and Math.Round (). These three methods follow the following rounding rules:
math.ceil () performs an upward rounding, that is, it always rounds the value up to the nearest integer;
math.floor () performs a downward rounding, that is, it always rounds the value down to the nearest integer;
Math.Round () performs a standard rounding, that is, it always rounds a number to the nearest integer (which is also the rounding rule we learned in math Class).
Here are a few examples:
math.ceil (25.9)
//26
math.ceil (25.5)
//26
math.ceil (25.1)
//26
math.ceil (25.0)
//25
math.round (25.9)
//26
math.round (25.5)
//26
math.round (25.1)
//25
math.floor (25.9)
//25
math.floor (25.5)
//25
Math.floor(25.1)
//25
Differences between several rounding methods of the math class in Java