ROUND()

Documentation

VoltDB Home » Documentation » Using VoltDB

ROUND()

ROUND() — Returns a numeric value rounded to the specified decimal place

Synopsis

ROUND( numeric-value, rounding-position )

Description

The ROUND() functions returns the input value rounded to the specific decimal place. The result is returned as a DECIMAL value.

The numeric-value argument must be a FLOAT or DECIMAL value. The rounding-position argument must be an integer between 12 and -25 and indicates the place to which the numeric value should be rounded. Positive values indicate a decimal place; for example 2 means round to 2 decimal places. Negative values indicate rounding to a whole number position; for example, -2 indicates the number should be rounded to the nearest hundred. A zero indicates that the value should be rounded to the nearest whole number.

Rounding is performed using "banker's rounding", in that any fractional half is rounded to the nearest even number. So, for example, if the rounding-position is 2, the value 22.225 is rounded to 22.22, but the value 33.335 is rounded to 33.34. The following list demonstrates some sample results.

ROUND (.123456789, 4) = 0.123500000000
ROUND( 123456789.123, 2 ) = 123456789.120000000000
ROUND( 123456789.123, 0 ) = 123456789.000000000000
ROUND( 123456789.123, -2 ) = 123456800.000000000000
ROUND( 123456789.123, -6 ) = 123000000.000000000000
ROUND( 123456789.123, 6 ) = 123456789.123000000000

Examples

The following example uses the ROUND() function to return a DECIMAL value, rounding the value of the budget column to two decimal places.

SELECT country, ROUND(budget,2) AS annual_budget 
    FROM world_economy ORDER BY country;