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
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.
To round a double to the nearest integer, just use round() .
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.
Have you checked Math.ceil(double)
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With