Why can I not convert the following string into a long? i am trying to do this in scala.
var a = "153978017952566571852"
val b = a.toLong
when I try to convert it I get the NumberFormatException
Because the number exceeds the limit of Long Integer which goes from -9223372036854775808 to 9223372036854775807, with maximum of 19 digits, while your string contains 21 digits.
You can convert it to Float or Double if you don't have to be exact:
scala> val b = a.toFloat
b: Float = 1.5397802E20
scala> val b = a.toDouble
b: Double = 1.5397801795256658E20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With