float(x) fails
hurak opened this issue · 0 comments
hurak commented
Calling float(x)
, which is among the examples of usage on the front page, gives an error:
julia> x = decimal(0.2)
Decimal(0, 2, -1)
julia> float(x)
ERROR: MethodError: no method matching tryparse(::Type{AbstractFloat}, ::String)
Closest candidates are:
tryparse(::Type{T<:Integer}, ::AbstractString; base) where T<:Integer at parse.jl:236
tryparse(::Type{Float64}, ::String) at parse.jl:247
tryparse(::Type{Float32}, ::String) at parse.jl:267
...
Stacktrace:
[1] #tryparse_internal#351(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(Base.tryparse_internal), ::Type{AbstractFloat}, ::String, ::Bool) at ./parse.jl:366
[2] tryparse_internal(::Type{AbstractFloat}, ::String, ::Bool) at ./parse.jl:366
[3] #parse#352(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(parse), ::Type{AbstractFloat}, ::String) at ./parse.jl:378
[4] parse(::Type{AbstractFloat}, ::String) at ./parse.jl:378
[5] AbstractFloat(::Decimal) at /home/hurak/.julia/packages/Decimals/YGhDp/src/decimal.jl:67
[6] float(::Decimal) at ./float.jl:271
[7] top-level scope at none:0
However, conversion to string works fine:
julia> string(x)
"0.2"
and therefore as a workaround one can use
julia> parse(Float64,string(x))
0.2
EDIT: It appears that the function float()
is not defined anywhere in the Decimals.jl
package (althgough it is used in the examples on the front page). Instead, obviously, number()
should be used.