how to convert Float to Integer in java?
Float value = 30.0F
how to convert above value to Integer?
Please help me?
Use Float.intValue():
Integer i = value.intValue();
Note that this causes autoboxing, but since you're planning to create an Integer anyway, this won't have any performance impact.
Note also that you should pay attention to rounding: intValue() and an int cast round toward zero. For rounding to the nearest integer, use Math.round(), for rounding down use Math.floor(), for rounding up use Math.ceil(). If you need some other kind of rounding, you need to implement it yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With