0

Hi! How i take the integer value of a float or double?

For example: n=2.85 Take the integer value of n Then m=2

28th Dec 2019, 5:05 AM
Víctor Laborin
Víctor Laborin - avatar
4 Réponses
+ 7
As Avinesh mentioned, use down casting to avoid rounding up as demonstrated here: https://code.sololearn.com/cXgQ9UltNHab/?ref=app
28th Dec 2019, 5:34 AM
David Carroll
David Carroll - avatar
+ 6
Type casting.
28th Dec 2019, 5:10 AM
Avinesh
Avinesh - avatar
+ 4
Martin Taylor The problem with using Math.floor() or Math.ceil() is they both return a double. So... both would still require a down cast when assigning to an int variable. Math.round() does return an int. However, I'm assuming the OP is trying to extract the whole number value on the left side of decimal.
28th Dec 2019, 3:13 PM
David Carroll
David Carroll - avatar