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 append to an array in JuliaLang?
- How to work with rational numbers in JuliaLang?
- How to test code in JuliaLang?
- How to measure execution time in JuliaLang?
- How to install JuliaLang?
- How to use the println function in JuliaLang?
- How to use channels in JuliaLang?
- How to sort in JuliaLang?
- How to reshape arrays in JuliaLang?
- How to use lambda functions in JuliaLang?
See more codes...