Conversion Query -- Decimal to Char/Varchar

Database
Vga
Enthusiast

Conversion Query -- Decimal to Char/Varchar

Hi,

I want to convert a Decimal field to a Char / Varchar. CAST & few other function are useful but in a scenario like:

Decimal value : -0.000124 (Minus sign at start position)

the output is coming as '-.000124'. I need the o/p to be '-0.000124'.

--GV

1 REPLY
Junior Contributor

Re: Conversion Query -- Decimal to Char/Varchar

You have to add a format:

cast((col (FORMAT '-(X)9.9(Y)')) as  char(...))

where X is the number of digits before the decimal separator and Y the fractional digits.

Dieter