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

Home » Public Forums » archive » Re: printing floats/integer
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: printing floats/integer [message #24096] Thu, 08 March 2001 14:44 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Sean Heukels" <sean77=cuthere=@dds.nl> writes:
> I wrote a small module for integers. The variable is formatted and returned.
>
> "1 " returns as "1"
>
> Now this doesn't work with floats. for example if I want to print "1.22221"
> I
> dont want to see it as "1.222221000000000000000" or
> "1.222222 "
>
> Does anyone know how I can solve this ??

The first thing to understand is that there are many real numbers
which cannot be represented in floating point number system of
computers. That's just the facts.

Second, if you simply don't want spaces around your numbers, why not
try STRTRIM?

One of the most sophisticated answers might be found in the following
paper by Burger and Dybvig, "Printing Floating-Point Numbers Quickly
and Accurately:"

http://citeseer.nj.nec.com/28233.html

Unfortunately that's probably overkill, and too hard to implement in
IDL.

You've seen Bob S's implementation. I have a program called INPUTFORM
on my web page which prints a number as a string, such that it can be
read again by the IDL parser. Like this:

IDL> print, inputform(1.22221)
1.22221E

You see the "E" indicates that it is a single-precision floating point
number, to distinguish it unambiguously from double precision or
integers. Just as Bob's code is not too pretty (sorry Bob), neither
is the code in INPUTFORM. Basically it tries printing the number with
both the "G" and "D" output formats and takes whichever is shorter.

Craig

INPUTFORM can be found at
http://cow.physics.wisc.edu/~craigm/idl/idl.html

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: contour labels question
Next Topic: Color 'n linestyle picker for Plot

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

Current Time: Wed Oct 08 14:58:33 PDT 2025

Total time taken to generate the page: 0.00186 seconds