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

Home » Public Forums » archive » Re: FORMAT FLOATS TO STRINGS WITH 3 DIGITS ONLY
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: FORMAT FLOATS TO STRINGS WITH 3 DIGITS ONLY [message #44188 is a reply to message #44159] Mon, 23 May 2005 06:09 Go to previous messageGo to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Giorgos wrote:
> Hi
>
> I have the following problem....
> I have an array of float numbers consisting of many decimal points and
> I want to convert it to string ... I used the string command but how
> can I isolate and keep only the first 3 digits from each element of the
> array? I played with the format keyword but... a mess...
> can anyone help?
>

If you want to print 3 digits after the decimal point and don't want any
leading spaces:

IDL> print, string(1.5345435435435, format='(f0.3)')

If you want only 3 significant digits and the number of digits before
the decimal point is not constant, you should go for scientific notation:

IDL> print, string(3432432.4343, format='(e0.2)')

(meaning two digits after the decimal point, making 3 significant digits)

You can also try the G format code, which uses scientific notation only
when necessary:

IDL> print, string(33432432.423423, format='(g0.3)')

(3 significant digits)

As far as I know, there is no format code which allows you to output
only X significant digits without using scientific notation at all.

The 0 in the format codes above makes the string just as long as
necessary (no leading spaces). If you want fixed width (padded with
spaces), give the number of characters you want in the string instead of
the 0 (which must include all the digits, the decimal point, the sign
and in scientific notation also the 'e').

Read the IDL help again about format codes, section "F, D, E, and G
format codes". It's quite confusing, but you'll need it all the time, so
why not tackle it now?

Good luck,
Benjamin
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: �����H�s�A�ȭp���R�Q�e�G.............
Next Topic: Adding an annotation to an iTool programmatically

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

Current Time: Sat Oct 11 00:56:42 PDT 2025

Total time taken to generate the page: 0.08377 seconds