Round numeric values to specified precision.
x
(numeric): The value to round. Can be Float*
, Decimal*
, or (U)Int*
.N
(numeric, optional): The number of decimal places to round to. Default is 0 (round to integer). Can be negative.x
.
Examples:
N
is non-negative, the function returns x
(does nothing).floor(-128, -1)
), the result is undefined.x
(numeric): The value to round. Can be a Float32
, Float64
, Decimal*
, or Int*
type.N
(Int
, optional): An integer specifying the number of decimal places to round to. Default is 0.x
. The return type is the same as the input type.
Examples:
N
is negative, the function rounds to the left of the decimal point. For example, ceiling(123.45, -1)
returns 130
.x
(numeric): The number to truncate. Can be Float*
, Decimal*
, or (U)Int*
.N
(Int
, optional): The number of decimal places to keep. Default is 0.
N > 0
, truncates to the right of the decimal point.N < 0
, truncates to the left of the decimal point.N = 0
, truncates to an integer.x
.
Example:
precise_price
shows the taco price truncated to 2 decimal places.rounded_hundreds
rounds down to the nearest hundred.menu_price
displays the taco prices on the menu, truncated to 1 decimal place.truncate
function always rounds towards zero, unlike floor
which rounds down, or ceil
which rounds up.x
(numeric): A number to round. Can be Float32
, Float64
, Decimal*
, or Int*
.N
(Int*
, optional): The number of decimal places to round to. Defaults to 0.
x
.
Description:
The function returns the nearest number of the specified order. If the input value has equal distance to two neighboring numbers, the function uses banker’s rounding for Float32
and Float64
inputs and rounds away from zero for other number types (Decimal*
and Int*
).
Example:
round
is used to round taco prices to one decimal place. Note how 2.75 rounds up to 2.8 (away from zero for Decimal
type), while 3.14 rounds down to 3.1.
Float32
and Float64
inputs, the function uses banker’s rounding when the value is exactly halfway between two numbers. For example:Float64
rounds to 4 (banker’s rounding to the nearest even integer), while 3.5 as a Decimal
also rounds to 4 (rounding away from zero).x
(numeric): A number to round. Can be Float*
, Decimal*
, or (U)Int*
.N
(Int
, optional): The number of decimal places to round to. Optional, defaults to 0.
N > 0
, rounds to the right of the decimal point.N < 0
, rounds to the left of the decimal point.N = 0
, rounds to the nearest integer.x
.
Description:
Banker’s rounding is a method of rounding fractional numbers where ties (numbers exactly halfway between two integers) are rounded to the nearest even integer. This method helps reduce bias in rounding operations.
For example:
roundBankers
rounds the taco prices to one decimal place using banker’s rounding. Note how 3.25 rounds to 3.2 instead of 3.3.
See Also:
x
(numeric): A number to round. Can be any numeric type.x < 1
, returns 0.x
rounded down to the nearest power of two.roundToExp2
rounds the number of tacos ordered down to the nearest power of two. This could be useful for grouping orders into size categories based on powers of two.
num
(UInt64
or Float64
): A number to round.UInt16
.roundDuration
is used to round the order_duration
(in seconds) to the nearest commonly used duration. This can be useful for grouping or categorizing order durations into standardized time intervals.
age
(UInt
or Float
): A number representing an age in years.UInt8
)
num
(numeric): The number to round down.arr
(Array
of UInt
or Float
): An array of elements to round down to.arr
.
Example:
roundDown
rounds each taco_price
to the nearest lower value in the array [3, 4, 5]
. Prices below 3 are rounded to 3, and prices above 5 are rounded to 5.