Monday 25 January 2016

Julia: Rounding functions

Julia provide following functions to round a real number to nearest integer.

Method
Description
round(x)
round x to the nearest integer.
round(T, x)
round x to the nearest integer of type T.
floor(x)
round x towards -Inf
floor(T, x)
round x towards –Inf of type T.
ceil(x)
round x towards +Inf.
ceil(T, x)
round x towards +Inf of type T.
trunc(x)
round x towards zero
trunc(T, x) 
round x towards zero of type T.


julia> round(10.3)
10.0

julia> round(Int64,10.3)
10

julia> floor(10.3)
10.0

julia> floor(Int32, 10.3)
10

julia> ceil(10.3)
11.0

julia> ceil(Int16, 10.3)
11

julia> trunc(10.3)
10.0

julia> trunc(10.9)
10.0

julia> trunc(Int32, 10.9)
10



Previous                                                 Next                                                 Home

No comments:

Post a Comment