Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Up Double to Whole Number?

Tags:

java

android

I have a double that contains the result of a calculation.

i.e 2.123 etc

Is there a simple way where i can round up this number to the next number up i.e 3

I have searched the forum, but only come up with how to round off to decimal places.

cheers

like image 818
Coops5575 Avatar asked Apr 16 '11 10:04

Coops5575


People also ask

How do you round up a double value?

Math. round() accepts a double value and converts it into the nearest long value by adding 0.5 to the value and truncating its decimal points. The long value can then be converted to an int using typecasting.

How do you round a double to the nearest integer in Swift?

To round a double to the nearest integer, just use round() .

How do you round up an integer?

Rounding to the Nearest Integer If the digit in the tenths place is less than 5, then round down, which means the units digit remains the same; if the digit in the tenths place is 5 or greater, then round up, which means you should increase the unit digit by one.


1 Answers

Have you checked Math.ceil(double) ?

like image 82
jmj Avatar answered Oct 13 '22 17:10

jmj