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

Home » Public Forums » archive » Re: Set Precision???????????
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: Set Precision??????????? [message #15786] Mon, 14 June 1999 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Anil Kochhar <anilk@mtolympus.ari.net> writes:
>
> Hi All
>
> I'd like create a varible which always holds numbers out to 6 places
> passed the decimal point, and 4 numbers before the decimal point (e.g.
> 1999.123456). I tried double
> precision but this seems to only hold 8 digits total for decimal numbers.
> However I would like to create a variable corresonding to a fraction of a
> Year (e.g 1995.123456). I have not been able to find a procedure allowing
> me to create 10 digit decimal number , without the number being rounded
> off to 8 digits.
> Does anyone know of a way to declare a variable to hold a 10 digit
> decimal number?

You should make a distinction between the *internal precision* of a
floating point or double precision number, and the *textual
representation* of that number. Both are quite different.

Internally, double precision maintains about 16 decimal digits in the
mantissa irrespective of the position of the decimal point, which is
plenty more than you need. [ Floating point keeps about 7 decimal
digits, probably not enough for you. ]

The important thing to keep in mind is that IDL doesn't always print
this many digits when it prints a number. I'm sure this is primarily
for convenience, since people probably don't want huge multi-digit
output on their screen most of the time.

By *default*, IDL prints 8 digits before the decimal, and 7 after the
decimal (at least it did in my simple trial). If you want to have a
different output format, then you need to tell IDL explicitly how to
format it using the FORMAT keyword to PRINT, PRINTF or STRING. That's
too complicated a subject to write about here but I can get you
started.

FORMAT strings are similar in spirit to IDL format statement in
FORTRAN, or the format string in C. For double precision output
formats, you describe (a) the total record length, and (b) the number
of digits after the decimal. In your case, the total record length is
11 ( = 4 year digits + 1 decimal point digit + 6 fractional digits),
and the number of digits after the decimal is 6. The format string is
thus 'D11.6'. Here is how that goes together in an IDL print
statement.

IDL> y = 1999.123456D
IDL> print, y
1999.1235
IDL> print, y, format='(D11.6)'
1999.123456

Voila!

Craig



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Previous Topic: Re: POLYWARP question.
Next Topic: device, true_color=24, decompose=0

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

Current Time: Thu Oct 09 13:50:56 PDT 2025

Total time taken to generate the page: 1.28304 seconds