to_decimal()

Scalar. Converts a boolean, integer, or money value to a decimal value with total digits and digits to the right of the decimal as specified.

Syntax

to_decimal ( value, precision, scale )

Parameters

value

A boolean, integer, or money value to be converted.

precision

A number, from 1 to 34, specifying the maximum number of digits that can be stored.

scale

A number, from 0 to precision, specifying the maximum number of digits that can be stored to the right of the decimal point.

Usage

Returns a decimal value equal to the input boolean, integer, or money value. If the input value fits in the specified decimal, the conversion succeeds. If it does not fit, the target value is set to NULL. Errors are reported on the error stream and the server.

Examples

to_decimal (integer 59111, 5, 0) returns 59111 with precision set to 5 and scale set to 0.

to_decimal (integer 59111, 5, 2) returns NULL because 59111 is greater than 999.99 which is the largest value that will fit in a decimal with the specified precision and scale.