TRUNCATE

Truncates the given input to a given number of decimal places.

Syntax

TRUNCATE(X [, N])

Arguments

X

Type: numeric

A numeric value.

N

Type: integer

Default: 0

The number of decimal places to keep. This can be negative to truncate N digits left of the decimal point.

If omitted, the precision defaults to 0 and X is rounded to the nearest integer.

Returns

Type: double

X truncated to PRECISION decimal places.


Examples

XPrecisionOutput

2.365

2.0

1.456249

3

1.456

42.01934

2

42.01

1.1

1.0

-1.1

-1.0

-1.9

-1.0

0

0.0

0.5

0.0

12.333

-1

10.0

12.333

0

12.0

12.333

1

12.3

Transformation job example

SQL

CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT 
        orderid,
        nettotal,
        TRUNCATE(nettotal, 0) AS trunc_nettotal
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;

Query result

orderidnettotaltrunc_nettotal

04xYsBwxOW

550.05

550

cu7qwoPA8q

1871.68

1871

dB91uTY7Vv

1538.02

1538

Last updated