Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android/Java: Rounding up a number to get no decimal

How to round up a decimal number to a whole number.

3.50 => 4

4.5 => 5

3.4 => 3

How do you do this in Java? Thanks!

like image 370
don Avatar asked Jul 09 '12 14:07

don


People also ask

How do you round off decimals in Java?

round() is used round of the decimal numbers to the nearest value. This method is used to return the closest long to the argument, with ties rounding to positive infinity.

How do you round up a value in Java?

Java Math round()The round() method rounds the specified value to the closest int or long value and returns it. That is, 3.87 is rounded to 4 and 3.24 is rounded to 3.


1 Answers

With the standard rounding function? Math.round()

There's also Math.floor() and Math.ceil(), depending on what you need.

like image 194
Oliver Charlesworth Avatar answered Oct 20 '22 17:10

Oliver Charlesworth