comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: formatting exponential notation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: formatting exponential notation [message #47957 is a reply to message #47956] Fri, 10 March 2006 08:03 Go to previous messageGo to previous message
David Fanning is currently offline  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/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How do I reduce active memory used by program?
Next Topic: Intel iMac IDL performance

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:28:32 PDT 2025

Total time taken to generate the page: 0.16142 seconds