0

One of the library is accepting only float value, so i am trying to convert integer value to float value in kotlin using toFloat() function. But it is giving nearest value and not the exact value. Official documentation also says

Returns the value of this number as a Float, which may involve rounding.

I am trying to convert 105312355 to Float, which is giving me 1.05312352E8. If i reverse calculate float to integer it is giving me 105312352.

So, how do i force to calculate correct value.

Rahul Gupta
  • 219
  • 3
  • 8

1 Answers1

1

The nature of Floating Point is that it can express a wider range of values at the expense of precision compared to the same size of Int.

Only a Double (rather than Float) can preserve the full precision of the Int. Something will need to give.

Duane
  • 86
  • 9