+ 8
How to round off a two decimal number to the nearest number?
67.12 =67 And. 52.51 =53 and not 52
5 Réponses
+ 6
double a = 45.67;
System.out.println((int)Math.round(a));
+ 2
import the math class to your project using the next line of code.
import java.lang.Math;
You can then round variable type double like you describe. the next line is an example where x holds the value you want to round.
System.out.println(Math.round(x));
+ 1
It’s been a while every since I did rounding back in my days but I’ll try to help you:
Round the number n to p decimal places by first shifting the decimal point in n by p places by multiplying n by 10ᵖ (10 raised to the p th power) to get a new number m . Then look at the digit d in the first decimal place of m . If d is less than 5, round m down to the nearest integer. Otherwise, round m up.
Just like Real life, check the number on your right (I mean the digits) if that digit on the right is 5 or higher then round it to the nearest 10s.
Example: 38 rounded to the nearest ten is 40.
Hope this helps 👌😄