Is there any way to ensure consistent formatting of arbitrary Floats and Doubles across platforms?
123.45f.toString()
has different rounding on wasmJs than other platforms, and
1.2e205.toString()
is
1.2E205
on most platforms, and
1.2+e205
on JS platforms (both browser and node).
đźš« 2
h
hfhbd
01/12/2025, 5:52 PM
There is no builtin function because Kotlin uses the platform representation that differs.
hfhbd
01/12/2025, 5:54 PM
Depending on the value you could convert it to a long and do the formatting yourself, but it is a very hacky workaround that should be avoided.
d
Daniel Pitts
01/12/2025, 8:46 PM
If I were going to work around it, it wouldn’t be by converting it to a long. Long can’t handle the 1.2e205 case.
I was just hoping there was some common utility for it, but if I want to have this feature, might just need to write it myself.