Re: formatting exponential notation [message #47956] |
Fri, 10 March 2006 08:42  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> So, anyway, long story short, I wrote a program called
> NUMBER_FORMATTER to to this for me. For my purposes, it
> works great. After I saw this post, I thought I would make
> it available on my web page.
>
> http://www.dfanning.com/programs/number_formatter.pro
After posting this, I noticed that my algorithm wasn't
rounding properly:
IDL> number = -2.343583743e-5
IDL> Print, Number_Formatter(number, DECIMALS=4)
-2.3435e-5
So I've just put up a new version that does this
correctly.
IDL> Print, Number_Formatter(number, DECIMALS=4)
-2.3436e-5
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: formatting exponential notation [message #47957 is a reply to message #47956] |
Fri, 10 March 2006 08:03   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Steve.Morris@libero.it writes:
> I need a quick advice on the way to write number in the exponent format
> I want.
> For example, I want the number printed on my screen in the following
> form
> -2.3435e-5
>
> i.e. 4 digits after the point and as function of e-5
>
> Any suggestion? I have tryed to use the format='(EX.X)' but without
> much of a success .... :(
There must be some kind of convergence going on in the
Universe today. Just yesterday I got sick and tired of
always having to figure out how to format numbers into
strings for my widget programs. I just want to print
the value of the image under the cursor! But I don't
know if the "image" is a byte array, a float array, or
even one of those damn FITS files as a double array!
Thus, I can't figure out how big to make the text widget
that holds all these numbers. Yuck!
So, anyway, long story short, I wrote a program called
NUMBER_FORMATTER to to this for me. For my purposes, it
works great. After I saw this post, I thought I would make
it available on my web page.
http://www.dfanning.com/programs/number_formatter.pro
It would work something like this for this example. In
the normal case it would use the number of significant
digits in a float. But with the DECIMALS keyword, you
can specify how many decimal places you would like in the
result. It always trims the exponent of leading zeros.
So e-008 comes out e-8, which I like better.
IDL> number = -2.343583743e-5
IDL> Print, Number_Formatter(number)
-2.343584e-5
IDL> Print, Number_Formatter(number, DECIMALS=4)
-2.3435e-5
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
|
Re: formatting exponential notation [message #48088 is a reply to message #47956] |
Mon, 20 March 2006 07:19  |
Steve.Morris@libero.i
Messages: 12 Registered: March 2006
|
Junior Member |
|
|
it looks like work very nicely in trimming the decimals, but can you
also set the exponent format?
Like, asking to have all numbers with e.g. 4 decimals and writted as
function of e-5 ?
so, if you have like 24.53214e-6 writte 2.4532e-5
Cheers, S.
|
|
|
Re: formatting exponential notation [message #48089 is a reply to message #47956] |
Mon, 20 March 2006 07:19  |
Steve.Morris@libero.i
Messages: 12 Registered: March 2006
|
Junior Member |
|
|
it looks like work very nicely in trimming the decimals, but can you
also set the exponent format?
Like, asking to have all numbers with e.g. 4 decimals and writted as
function of e-5 ?
so, if you have like 24.53214e-6 writte 2.4532e-5
Cheers, S.
|
|
|