+ 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
6 Respuestas
+ 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);
+ 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
+ 1
Thanks zexu knub
+ 1
Thanks zemiak
+ 1
Thanks
It means a lot Martin Taylor