F# - Convert a char to int

Assuming you've validated the character and know that it's an ASCII digit, you can do the following:

let inline charToInt c = int c - int '0'

let c = '3'
c |> charToInt

Online Demo

N.b. if you ultimately need a float rather than an int there is a built-in mechanism: System.Char.GetNumericValue


If you're trying to convert a -> 0, b -> 1, ....., z -> 26. Then you could do this

let let2nat (letter : char) = int letter - int 'a'

If you just want the ascii you can do this

let let2ascii (let2ascii : char) = int let2ascii