4

I want to append trailing '0' to number while performing Select query:

what I want is to select

344.89 as 344.890

123213.45 as 123213.450

1.2 as 1.200

I tried using to_char(col_name,'000000.000') but that resulted in

344.89 => 000344.890

123213.45 => 123213.450

1.2 => 000001.200

there were unwanted '0' appended to the result.

Community
  • 1
  • 1
Manish
  • 1,946
  • 2
  • 24
  • 36
  • 2
    What should happen with `344.891` or `344.8901`? http://stackoverflow.com/questions/6662153/how-to-expand-decimal-places-of-a-number-to-a-minimum-in-oracle-plsql – Tim Schmelter Aug 28 '13 at 12:53
  • Duplicate of http://stackoverflow.com/questions/6662153/how-to-expand-decimal-places-of-a-number-to-a-minimum-in-oracle-plsql – Darkzaelus Aug 28 '13 at 12:56

1 Answers1

9

You are close with the to_char format. Try this:

to_char(col_name,'999999.000')

The 9s represent optional place holders. The 0s represent putting in leading zeros.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • That is working fine, so there can't be solution for any number of digits before the decimal, as in this solution there will be a problem if there are more than 6 digits before decimal. say 2749308.23 – Manish Aug 28 '13 at 13:24