TO_DECIMAL

Description

Converts the input value to a Decimal. If the input cannot be converted, the function throws an error.

Syntax

TO_DECIMAL(string/double/long/float/integer, scale_optional) -> Decimal

Parameters

ParameterData TypeRequiredDescription
string/double/long /float/integerString/Double/Long /Float/IntegerYesThe string to convert into a Decimal
scale_optionalIntegerNoThe number of decimal places to round to. If omitted, no rounding occurs.

Examples

TO_DECIMAL("25.6789")
-- Returns 25.6789.
TO_DECIMAL(123.456789, 3)
-- Returns 123.457, rounded to 3 decimal places.
TO_DECIMAL(3147483647, 2)
-- Returns 3147483647.00.
TO_DECIMAL(10/3, 3)
-- Returns 3.333, rounded to 3 decimal places.
TO_DECIMAL(75, 3)
-- Returns 75.000.

Tips

  • If the input is a string, it must represent a valid number; otherwise, an error will occur.