Home > Software engineering >  Convert Negative String into Float in Kotlin?
Convert Negative String into Float in Kotlin?

Time:08-24

I haven't seen any questions on StackOverflow that pertain to this question specifically in Kotlin. I am getting a crash

java.lang.NumberFormatException: For input string: "−0.15"

when I try string.toFloat(), what is the best solution in Kotlin?

CodePudding user response:

Your minus sign isn't ordinary hyphen-minus symbol, replace your minus sign to the normal one:

"−0.15".replace("−", "-").toFloat()
  • Related