I am trying to convert a string to integer using String.toInt. However, when I want to bind the result to a variable and then do some simple math with it I get this error:
Function
add
is expecting the 2nd argument to be:Int
But it is:
Result String Int
How can I just extract the integer part of the result?
The atoi() function converts a character string to an integer value.
The method generally used to convert String to Integer in Java is parseInt() of String class.
Here's how to supply the conversion with a default value in case the parsing fails.
String.toInt "5" |> Result.toMaybe |> Maybe.withDefault 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With