floor
.. floor([T,] x, [digits, [base]])
``floor(x)`` returns the nearest integral value of the same type as ``x``
that is less than or equal to ``x``.
``floor(T, x)`` converts the result to type ``T``, throwing an
``InexactError`` if the value is not representable.
``digits`` and ``base`` work as for :func:`round`.Examples
The floor function in Julia:
floor(x)
returns the nearest integral value of the same type as x that is less than or equal to x.
floor(T, x)
converts the result to type T, throwing an InexactError if the value is not representable.
The optional arguments digits and base work as they do for the round function.
Here are some examples of how the floor function can be used:
-
Basic usage with integers:
julia> floor(5) 5 julia> floor(8.9) 8The
floorfunction returns the nearest integral value that is less than or equal to the input number. -
Conversion to a specific type:
julia> floor(Int, 5.6) 5 julia> floor(Float32, 7.8) 7.0Using
floor(T, x), we can convert the result to a specific type. If the value is not representable, it throws anInexactError. -
Usage with
digitsandbase:julia> floor(3.14159, digits=3) 3.141 julia> floor(123.456, base=10) 120.0The
digitsargument specifies the number of significant digits to consider, and thebaseargument determines the rounding base.
And that's how you can use the floor function in Julia!
See Also
abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.