julialangHow to round numbers in JuliaLang?
JuliaLang provides a number of functions to round numbers.
The most commonly used function is round(x), which rounds the number x. For example:
julia> round(3.14159)
3.0
Other rounding functions include ceil, floor, trunc and round(Int, x).
ceil(x)roundsxup to the nearest integer.floor(x)roundsxdown to the nearest integer.trunc(x)roundsxtowards zero.round(Int, x)roundsxto the nearest integer of typeInt.
For example:
julia> ceil(3.14159)
4.0
julia> floor(3.14159)
3.0
julia> trunc(3.14159)
3.0
julia> round(Int, 3.14159)
3
Helpful links
More of Julialang
- How to test code in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to use tuples in JuliaLang?
- How to use try catch in JuliaLang?
- How to use channels in JuliaLang?
- How to calculate the mean in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to use interpolation in JuliaLang?
- How to install JuliaLang on Linux?
See more codes...