Round float with Julia 1.1

Hello, I am trying to round a number to the 3rd decimal with Julia 1.1 but I have issues:

julia> beta
0.005208333333333333
julia> round(beta, 3)
ERROR: MethodError: no method matching round(::Float64, ::Int64)
Closest candidates are:
  round(::Float64, ::RoundingMode{:Nearest}) at float.jl:370
  round(::Float64, ::RoundingMode{:Up}) at float.jl:368
  round(::Float64, ::RoundingMode{:Down}) at float.jl:366
  ...
Stacktrace:
 [1] top-level scope at none:0
julia> round(beta, Up)
ERROR: UndefVarError: Up not defined
Stacktrace:
 [1] top-level scope at none:0
julia> round(beta, RoundingMode(Up))
ERROR: UndefVarError: Up not defined
Stacktrace:
 [1] top-level scope at none:0
julia> RoundNearest(beta)
ERROR: MethodError: objects of type RoundingMode{:Nearest} are not callable
Stacktrace:
 [1] top-level scope at none:0
julia> round(beta, RoundNearest)
0.0
julia> ceil(beta)
1.0

what is the current sintax to round a float to the n digit?

julia> round(1.3333333333333333, digits=3)
1.333
1 Like

You’re probably looking to old documentation? round(beta, 3) is an old syntax, before Julia v0.7

Relevant documentation is here.

To be fair though, this table about rounding functions links to the TimeType-related (ie dates) methods for round, which is probably a bit confusing. Should this be fixed?

1 Like