DecimalParser

Turns a decimal string into the nearest double, rounding halves to even, on every target.

The platform's own String.toDouble is not good enough. Kotlin/Wasm answers a neighbouring double for about one string in a hundred, mostly but not only in the subnormal range, and a JavaScript engine that reads 5.65865417e-315 as a different number than the JVM does is not the same engine. This is the last conversion the port asked a platform for.

Two paths. Almost every literal a script contains takes the first one.

Functions

Link copied to clipboard
fun parse(text: String): Double?

Parses text, which the caller has already checked contains only digits, a dot, an exponent marker and signs. Returns null when it is not a decimal number after all.