https://kotlinlang.org logo
#javascript
Title
# javascript
l

louiscad

03/17/2023, 4:11 PM
Hello,
print(0.0.toString())
prints
0.0
on the JVM, but
0
on JS. Is there an alternative to
toString()
to get
0.0
on JS as well?
e

ephemient

03/17/2023, 4:43 PM
doesn't seem like there is
I suppose you could do a hack like like
Copy code
fun Double.toStringInFloatingPointNotation(): String {
    val string = toString()
    return if ('.' in string || 'e' in string || !isFinite()) string else "$string.0"
}
4 Views