Android Dev
Android Dev

Reputation: 535

Convert Negative String into Float in Kotlin?

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?

Upvotes: 1

Views: 533

Answers (1)

Vadik Sirekanyan
Vadik Sirekanyan

Reputation: 4622

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

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

Upvotes: 4

Related Questions