0

What is the difference between floor() and rint() functions.

Can anyone pls help me to understand the differences between them

19th Mar 2019, 8:15 AM
Ujjwal Kumar
Ujjwal Kumar - avatar
1 Answer
0
I hadn’t heard of rint() so I will start with floor() In maths, the floor and ceiling functions are used to round to the nearest whole number. Think of a room: the floor will be my lowest point and the ceiling the highest floor(4.95) = 4 ceiling(4.95) = 5 floor(8.05) = 8 ceiling(8.05) = 9 floor(10) = ceiling(10) = 10 (ceiling in Java and JavaScript is ceil() ) As for rint(): this appears to round down but to the nearest even integer Math.rint(4.2) = 4.0 Math.round(4.2) = 4 Math.rint(4.5) = 4.0 Math.round(4.5) = 5 Math.rint(4.501) = 5.0 Math.round(4.501) = 5 which i agree with a commenter asking here why would you want that :’) stackoverflow.com/questions/37256550/difference-between-math-rint-and-math-round-in-java/37257027
20th Mar 2019, 8:00 PM
Jenine