Oracle display value before decimal for 0's

Viewed 24

For exmaple: select 'A='||(0.22*0.11)||'' as A from dual; it does return A=.0242 expected A=0.0242enter code here

1 Answers

If you use to_char function with desired format mask, then you get

SQL> select 'A='|| to_char(0.22*0.11, 'fm999G990D0000')||'' as A from dual;

A
---------------
A=0,0242

SQL>

As of a "generic" format model: you can't "dynamically" set it, but - if you use 9 instead of 0 after decimal point, you might get what you wanted:

SQL> select 'A='|| to_char(88.223*99.112, 'fm999G990D9999999999')||'' as A from dual;

A
---------------------
A=8.743,957976

SQL>
  • Benefit: it returns result you want
  • Drawback: how many 9s will you have to put in there? You can't tell - set it to the "worst" case you expect (such as 10 of them in my example)
Related