Updated on 2023-10-25 GMT+08:00

round

This function is used to calculate the rounded value of a up to d decimal places.

Syntax

round(DOUBLE a, INT d)

Parameters

Table 1 Parameters

Parameter

Mandatory

Type

Description

a

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

It indicates the value to be rounded off.

The value can be a float, integer, or string.

d

No

INT

The default value is 0.

It indicates the number of decimal places to which the value needs to be rounded.

If the value is not of the INT type, the system will implicitly convert it to the INT type for calculation.

Return Values

The return value is of the DOUBLE type.

  • If the value of d is negative, an error is reported.
  • If the value of a or d is NULL, NULL is returned.

Example Code

The value 123.0 is returned.

select round(123.321);

The value 123.4 is returned.

select round(123.396, 1);

The value NULL is returned.

select round(null);

The value 123.321 is returned.

select round(123.321, 4);

The value 123.3 is returned.

select round(123.321,1.33333);

The value 123.3 is returned.

select round(123.321,1.33333);