+ 1

What is the difference between round() and rint() in java

I studied that round gives an integer value but it does not give. It says it takes fractional value. https://code.sololearn.com/caZPnQob3gBt/?ref=app

10th Oct 2021, 4:35 AM
Ananya | Inactive |
Ananya | Inactive | - avatar
6 ответов
+ 2
Round is giving the integer as it removing the extra values after the . precision but it is not converting it to the integer for that you have to do explicit conversation to int. int b = (int)Math.round(45.7);
10th Oct 2021, 4:46 AM
zexu knub
zexu knub - avatar
+ 2
try this Object a = Math.rint( -1.5); Object b = Math.round(-1.5); System.out.println( a.getClass() ); //Double System.out.println( b.getClass() ); //Long System.out.println( a); // -2.0 System.out.println( b); // -1
10th Oct 2021, 7:17 AM
zemiak
+ 1
Thanks zexu knub
10th Oct 2021, 5:29 AM
Ananya | Inactive |
Ananya | Inactive | - avatar
+ 1
Thanks zemiak
10th Oct 2021, 11:58 AM
Ananya | Inactive |
Ananya | Inactive | - avatar
+ 1
Thanks It means a lot Martin Taylor
11th Oct 2021, 12:07 PM
Ananya | Inactive |
Ananya | Inactive | - avatar