Reputation: 2393
I want to convert float to 14 significant digits
val s = "1200000000".toFloat
Output-1.2E9
I tried below but does not work
f"$s%1.0f"
but this doesnot work with all values
I want a method which takes in string and return a float .The method can support upto 15 significant digits
Upvotes: 0
Views: 3541
Reputation: 3068
You can use toPlainString method of java.math.BigDecimal:
val floatValue = "1200000000".toFloat
new java.math.BigDecimal(floatValue).toPlainString
res0: String = 1200000000
Upvotes: 3