I would like to replicate the functionality of python function int() which can convert either string or float to a int type with base of 10.
Reference: https://www.w3schools.com/python/ref_func_int.asp
I have developed a small code to perform this execution:
a = "5.9"
print("Type of a = ", typeof(a))
if typeof(a) == String
x1 = reinterpret(Int64, a) # 1st attempt
x1 = parse(Int, a) # 2nd attempt
else
x1 = floor(Int64, a)
end
print("\nx1 = $x1", ",\t","type of x1 = ", typeof(x1))
In the above code, I have shown the functions to convert the string to int type but neither works.
Please do suggest a solution which can convert the string to int and also for any recommendation to optimize the above code?
Thanks!