|
|
Archives of the TeradataForum
Message Posted: Wed, 26 Jul 2006 @ 13:55:46 GMT
Subj: | | Re: Formatting a number using engineering notation |
|
From: | | Victor Sokovin |
| Is it possible to format a number using engineering notation (scientific notation in which the power of ten must be a multiple of
three)? | |
The following is meant as just a rough idea; I have not tested it to any significant extent. You may need to change the formats, rounding rules
etc according to your requirements.
select (coalesce(MOD1,''))
|| (coalesce(MOD2,''))
|| (coalesce(MOD0,'')) Engineering_Notation
from
(
select 15000 N, log(N) (int) R,
case R mod 3 when 1 then N else NULL end
(format '99.99e99') (varchar(10)) MOD1,
case R mod 3 when 2 then N else NULL end
(format '.99e99') (varchar(10)) MOD2,
case R mod 3 when 0 then N else NULL end
(format '9.99e99') (varchar(10)) MOD0
) DT;
*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.
Engineering_Notation
------------------------------
15.00E03
select (coalesce(MOD1,''))
|| (coalesce(MOD2,''))
|| (coalesce(MOD0,'')) Engineering_Notation
from
(
select 150000 N, log(N) (int) R,
case R mod 3 when 1 then N else NULL end
(format '99.99e99') (varchar(10)) MOD1,
case R mod 3 when 2 then N else NULL end
(format '.99e99') (varchar(10)) MOD2,
case R mod 3 when 0 then N else NULL end
(format '9.99e99') (varchar(10)) MOD0
) DT;
*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.
Engineering_Notation
------------------------------
.15E06
select (coalesce(MOD1,''))
|| (coalesce(MOD2,''))
|| (coalesce(MOD0,'')) Engineering_Notation
from
(
select 1500000 N, log(N) (int) R,
case R mod 3 when 1 then N else NULL end
(format '99.99e99') (varchar(10)) MOD1,
case R mod 3 when 2 then N else NULL end
(format '.99e99') (varchar(10)) MOD2,
case R mod 3 when 0 then N else NULL end
(format '9.99e99') (varchar(10)) MOD0
) DT;
*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.
Engineering_Notation
------------------------------
1.50E06
In all these cases the exponents are multiples of 3. I understand that was the main part of the question, right?
Regards,
Victor
| |