Converter to Double

Report a typo

Consider a function that takes a string and converts it to a double. If the input string is empty or has a wrong format, a runtime exception occurs and the program fails.

Fix the function so that it catches any exceptions and returns the default value 0 (zero) if an exception occurred.

Sample Input 1:

123.0

Sample Output 1:

123.0

Sample Input 2:

d

Sample Output 2:

0.0
Write a program in Kotlin
fun convertStringToDouble(input: String): Double {
/**
* It returns a double value or 0 if an exception occurred
*/
return input.toDouble()
}
___

Create a free account to access the full topic