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
jw
06/14/2024, 3:00 AM
Long is boxed. Double matches JS's native number type.
thank you color 1
e
ephemient
06/14/2024, 3:43 AM
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
ephemient
06/14/2024, 3:48 AM
for the most part I'd just go with whatever's more convenient for the API you're working with
ephemient
06/14/2024, 3:49 AM
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
Tóth István Zoltán
06/14/2024, 6:05 AM
Thanks, I'll switch to double then, it seems better.