What is best way to convert “33.2” as a string to ...
# android
t
What is best way to convert “33.2” as a string to int?
v
“33.2”.toFloat().toInt()?
m
"33.2".substringBefore(".").toInt()
But probably Vitaliy's solution is better
s
@jose’s solution would have different behaviors for negative numbers, i.e. always rounding up
👍 2
j
Wrong @jose
s
Ouch, sorry
f
How about defining a decimalformat for your app and parsing string into bigdecimal then to an integer That way you can handle different kinds of strings “33,2 - 33.2” and it wouldn’t overflow (till you cast it to int)