Converting String to Number in Julia
Code
To convert a string str to a number of type type, use parse(type, str).
julia> parse(Int, "21")
21
julia> parse(Float64, "3.14")
3.14
You might wonder why we can’t do something like Int64("21") as in Python… That’s because changing ‘“21”’ into 21 is not about changing types but interpreting the string "21" as a number, which justifies the use of parse1.
Environment
- OS: Windows
- julia: v1.6.3
