SQL numeric and rounding functions
Calculate and round numeric values in Haybarn SQL, with examples that distinguish exact decimals from floating point numbers.
Choose a function
Choose the numeric type before the formula. Use a suitable DECIMAL precision and scale for exact decimal quantities, and floating point types when approximate arithmetic is appropriate.
round()Round to a chosen decimal precision.floor()Move down to an integer boundary.ceil()Move up to an integer boundary.abs()Measure magnitude without the sign.
Rounding each input can produce a different total from rounding the final sum. Decide which rule your calculation needs and keep it consistent.
Round numbers to decimal places
Round a numeric value to a chosen number of decimal places. A negative precision rounds to tens, hundreds, or larger units.
NULL stays NULL. For exact decimal inputs, halfway values round away from zero.
Guide example · Run to view results.
| amount | nearest_ten | missing |
|---|---|---|
12.35 | 130 | NULL |
Watch for: Floating point values can be approximate. Use DECIMAL for examples where the exact decimal halfway point matters.
All numbers & math functions
55 functions in Haybarn WASM 2.0.0-rc12. Browse the filtered catalog →
abs()Absolute value
acos()Computes the arccosine of x
acosh()Computes the inverse hyperbolic cos of x
add()asin()Computes the arcsine of x
asinh()Computes the inverse hyperbolic sin of x
atan()Computes the arctangent of x
atan2()Computes the arctangent (y, x)
atanh()Computes the inverse hyperbolic tan of x
bit_count()Returns the number of bits that are set
bit_position()Returns first starting index of the specified substring within bits, or zero if it is not present. The first (leftmost) bit is indexed 1
cbrt()Returns the cube root of x
ceil()Rounds the number up
ceiling()Rounds the number up
cos()Computes the cos of x
cosh()Computes the hyperbolic cos of x
degrees()Converts radians to degrees
divide()even()Rounds x to next even number by rounding away from zero
exp()Computes e to the power of x
factorial()Factorial of x. Computes the product of the current integer and all integers below it
floor()Rounds the number down
fmod()gcd()Computes the greatest common divisor of x and y
greatest_common_divisor()Computes the greatest common divisor of x and y
isfinite()Returns true if the floating point value is finite, false otherwise
isinf()Returns true if the floating point value is infinite, false otherwise
isnan()Returns true if the floating point value is not a number, false otherwise
lcm()Computes the least common multiple of x and y
least_common_multiple()Computes the least common multiple of x and y
ln()Computes the natural logarithm of x
log()Computes the logarithm of x to base b. b may be omitted, in which case the default 10
log10()Computes the 10-log of x
log2()Computes the 2-log of x
mod()multiply()pi()Returns the value of pi
pow()Computes x to the power of y
power()Computes x to the power of y
radians()Converts degrees to radians
random()Returns a random number between 0 and 1
round()Round a numeric value to a chosen number of decimal places. A negative precision rounds to tens, hundreds, or larger units.
round_even()Rounds x to s decimal places, rounding halfway cases to the nearest even digit
roundbankers()Rounds x to s decimal places, rounding halfway cases to the nearest even digit
setseed()Sets the seed to be used for the random function
sign()Returns the sign of x as -1, 0 or 1
signbit()Returns whether the signbit is set or not
sin()Computes the sin of x
sinh()Computes the hyperbolic sin of x
sqrt()Returns the square root of x
subtract()tan()Computes the tan of x
tanh()Computes the hyperbolic tan of x
trunc()Truncates the number
truncate_duckdb_logs()