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

Home » Public Forums » archive » Re: Most significant digit and formatting floating point output
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: Most significant digit and formatting floating point output [message #81094 is a reply to message #81093] Tue, 07 August 2012 06:44 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Helder writes:

> well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).
> Here are two versions of the same question:
> 1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure this out with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.
>
> 2) Long version: I'm analyzing some images and I get results with errors. These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units' and the source data is:
> Result = 0.123456789
> Error = 0.003456789
> The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat = '(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRIM(FirstNonZ eroElement,2)+')'
> and use "MyFormat" as formatting for the string conversion of both.
> (in the above example FirstNonZeroElement should be 3 and MyFormat would be '(f05.3)'.

You might be interested in the Number_Formatter program
in the Coyote Library:

http://www.idlcoyote.com/programs/number_formatter.pro

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Substituting multiple strings into a program
Next Topic: append files

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

Current Time: Sun Oct 12 05:15:06 PDT 2025

Total time taken to generate the page: 0.04866 seconds