Home > other >  Oracle Apex - Format number in millions
Oracle Apex - Format number in millions

Time:08-13

Is there a way to use Currency Format (or some other standard formatter) to format numbers like this in Oracle Apex:

1,000,000 => 1.00M

1,234,567 => 1.23M

1,234,567,890 => 1234.57M

CodePudding user response:

Not declaratively, as far as I can tell. But, you can do it yourself (perhaps).

  • col is original value
  • c1 is that number (col) divided by a million
  • c2 rounds the result to the 2nd decimal (which is OK, but - decimals are missing (see 1)
  • c3 uses to_char function
  • final_result is c3 concatenated with an M

Note that col, c1 and c2 are numbers, while c3 and final_result are strings.

SQL> with test (col) as
  2    (select 1000000 from dual union all
  3     select 1234567 from dual union all
  4     select 1234567890 from dual
  5    )
  6  select col,
  7    col/1e6 c1,
  8    round(col/1e6, 2) c2,
  9    to_char(col/1e6, 'fm99990D00') c3,
 10    --
 11    to_char(col/1e6, 'fm99990D00') || 'M' final_result
 12  from test;

       COL         C1         C2 C3        FINAL_RESULT
---------- ---------- ---------- --------- ---------------
   1000000          1          1 1,00      1,00M
   1234567   1,234567       1,23 1,23      1,23M
1234567890 1234,56789    1234,57 1234,57   1234,57M

SQL>
  • Related