How to do String to number conversion in Kotlin JS app. I am Using the following code and having some trouble converting from the HTMLInputElement value to double.
fun c2f(self: Any) {
console.log("Self object: ${self} ")
val celsius = document.getElementById("celcius")?.getAttribute("value") as Double
val fahrenheit = celsius * 1.8 + 32
console.log("Fahrenheit value: ${fahrenheit} ")
window.alert("Celcius (${celsius}) -> Fahrenheit (${fahrenheit}) ")
}
- Also i am not seeing any
toDouble()function onStringclass as in the case of JVM app.
String.toDouble(): Doublefunction in stdlib on JVM (github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/…). Note that it is an extension function, so it is not in theStringclass. You can find it easily via the code completion. More on extensions: kotlinlang.org/docs/reference/extensions.html