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
4 Answers
+ 7
As Avinesh mentioned, use down casting to avoid rounding up as demonstrated here:
https://code.sololearn.com/cXgQ9UltNHab/?ref=app
+ 6
Type casting.
+ 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.