I'm wondering what data type to use when working w...
# multiplatform
t
I'm wondering what data type to use when working with low level UI Float or Double? • iOS - Double • Android - Float or Integer • JS (browser) - I have no idea but as I remember Double is boxed in Kotlin/JS. On top of that Path2D in browsers uses Double As of know I use Float in my code and convert it to the appropriate data type when I call platform dependent code. Is this a good idea or should I switch to Double?
j
Long is boxed. Double matches JS's native number type.
thank you color 1
e
Float is usually good enough - you shouldn't notice the difference in precision in the UI Double is also fine - it's mostly not slower than Float and the only downside is taking more memory
for the most part I'd just go with whatever's more convenient for the API you're working with
also it's not even a real choice on JS, Float is secretly a JS Number, same as Double.
Copy code
val x = 1f
val y = 1.0000000000000002
println(x == y.toFloat())
is
true
on Kotlin/JVM,
false
in Kotlin/JS
👍 1
thank you color 1
t
Thanks, I'll switch to double then, it seems better.
👍 1