Home > front end >  sql cast to str with zero after dot
sql cast to str with zero after dot

Time:03-11

How can i get '186.60' string from 186.6 number in sql ?

select( 186.6::varchar);

result is

'186.6'

CodePudding user response:

Using to_char() from Data formatting functions.

 select to_char(186.6, 'FM999D90');
 to_char 
---------
 186.60

Where 9 represents not significant digits and 0 represents significant digits. The FM(fill mode) preserves leading and trailing zeros.

CodePudding user response:

select(162.4::numeric(10,2)::varchar);

will return

162.40
  • Related