Why does To_char(3E4) not result in '3E4'?

Asked

Viewed 37 times

3

Guys like me convert an exponential number (NUMBER) to string (VARCHAR) but it is expressed equal??

Example:

SQL> SELECT   TO_CHAR (NUMERO) NUMCONVERT
  2    FROM   (SELECT   3E4 NUMERO FROM DUAL);

NUMCONVERT
----------------------------------------
30000

How to return '3E4'??

2 answers

1

  • I also tried to use this way but after it is converted gets '3.0E+04' I needed '3E4' expressed equal to the integer.

0

Using only the TO_CHAR(numero,'FM9.9EEEE'), returns:

3.E+04

But since you want it to stay the same, I made one Gambiarra:

   SELECT REPLACE(
             REPLACE(
                REPLACE(TO_CHAR(numero,'FM9.9EEEE'),
                'E+0','e')
             ,'E+','e')
           ,'.','') numconvert
      FROM (SELECT 3e4 as numero
              FROM dual);

Returning:

3e4

I hope it helps.

  • Even would David, the problem is that it is not specifically 3E4. It will have values like: 1E-1, 1.67E-1, 1.99E1....

  • The other answer will help you better, otherwise we’ll have a lot of REPLACE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.