float a=8.61f;
int b;
b=(int)a;
This is how you change float to int. It's not accurate.
The value of b is 8, but it's supposed to be 9. And when the value of a is -7.65f, the result is -7, not -8
What should I do to properly change my brother?
floating-point java int
Use Math.round(). Round the float to the nearest whole number.
© 2024 OneMinuteCode. All rights reserved.