Is there any way to ensure consistent formatting o...
# multiplatform
d
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
There is no builtin function because Kotlin uses the platform representation that differs.
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
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.