What is best way to convert “33.2” as a string to int?
v
vkholyavin
10/16/2018, 9:41 PM
“33.2”.toFloat().toInt()?
m
mccorby
10/16/2018, 9:43 PM
"33.2".substringBefore(".").toInt()
mccorby
10/16/2018, 9:44 PM
But probably Vitaliy's solution is better
s
Seri
10/16/2018, 9:48 PM
@jose’s solution would have different behaviors for negative numbers, i.e. always rounding up
👍 2
j
jose
10/17/2018, 6:15 AM
Wrong @jose
s
Seri
10/17/2018, 6:45 AM
Ouch, sorry
f
fatih.yalmanbas
10/17/2018, 2:32 PM
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)