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)
roundsx
up to the nearest integer.floor(x)
roundsx
down to the nearest integer.trunc(x)
roundsx
towards zero.round(Int, x)
roundsx
to 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 measure execution time in JuliaLang?
- How to set up logging in JuliaLang?
- How to test code in JuliaLang?
- How to use enums in JuliaLang?
- How to append to an array in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to use channels in JuliaLang?
- How to sort in JuliaLang?
- How to use dictionaries in JuliaLang?
- How to use the println function in JuliaLang?
See more codes...