f



problem string from double missing digits

Hi all,

did someone know what here is going on.

IDL> d = 98046763.617D
IDL> s = string(d)
IDL> PRINT,s
        98046764.
IDL> HELP,s
S               STRING    = '       98046764.'

Where are the digits ????

Or does it mean I have first to determine the Format of the number and I 
have to use this information to get the right number.

IDL> s = string(d,format='(F12.3)')
IDL> PRINT,s
98046763.617

This goes right. But my feeling is this is terrible. Because I bet noone
takes care on this. What's your feeling?


regards

Reimar

-- 
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
-------------------------------------------------------------------
         a IDL library at ForschungsZentrum Juelich
  http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro.html
===================================================================

0
R.Bauer (610)
9/11/2003 12:45:22 PM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

4 Replies
656 Views

Similar Articles

[PageSpeed] 0

Reimar Bauer wrote:
> 
> Hi all,
> 
> did someone know what here is going on.
> 
> IDL> d = 98046763.617D
> IDL> s = string(d)
> IDL> PRINT,s
>         98046764.
> IDL> HELP,s
> S               STRING    = '       98046764.'
> 
> Where are the digits ????
....
> Or does it mean I have first to determine the Format of the number and I
> have to use this information to get the right number.

If you don't like the default format, you do have to specify the
particular alternative you wish to use. However, you don't have to be
explicit:

IDL> PRINT,string(d,FORMAT='(F)')
98046763.6169999990000000

That's overkill, but at least you didn't lose anything. Coming from a C
background, I personally prefer:

IDL> PRINT,string(d,FORMAT='(%"%f")')
98046763.617000

....
> This goes right. But my feeling is this is terrible. Because I bet noone
> takes care on this. What's your feeling?

My feeling is that you'd lose your bet. Almost everyone who spends much
time printing floating point numbers ends up sooner or later having to
override the default formats.
0
kuyper (156)
9/11/2003 1:10:14 PM
Reimar Bauer <R.Bauer@fz-juelich.de> writes:
> 
> Where are the digits ????
> 
> Or does it mean I have first to determine the Format of the number and I 
> have to use this information to get the right number.
> 
> IDL> s = string(d,format='(F12.3)')
> IDL> PRINT,s
> 98046763.617
> 
> This goes right. But my feeling is this is terrible. Because I bet noone
> takes care on this. What's your feeling?

No you don't need to figure out the number of significant digits,
since you can use the format code 'D0'.  Formatting output properly is
ultimately the programmer's job.  As you did, one rapidly discovers
when they get the formatting wrong.

By the way, why use the 'F' format code, when you know that you have
more than 7 significant digits?  Aside question to the group: are the
'F' or 'D' format codes any different?

Good luck,
Craig
0
9/11/2003 1:12:19 PM
In article <bjpqp2$fhrl$1@zam602.zam.kfa-juelich.de>,
 Reimar Bauer <R.Bauer@fz-juelich.de> wrote:

> Hi all,
> 
> did someone know what here is going on.
> 
> IDL> d = 98046763.617D
> IDL> s = string(d)
> IDL> PRINT,s
>         98046764.
> IDL> HELP,s
> S               STRING    = '       98046764.'
> 
> Where are the digits ????

The default (free-form) formats are G13.6 for FLOATs and G16.8 for 
DOUBLEs.  If you need more places to the right of the decimal point, you 
have to use an explicit format.  (Building IDL Applications, v. 5.6, p. 
234)

"G   -  Use F or E format depending on the magnitude of the value being
processed."


IDL> d = 98046763.617D
IDL> print, d, FORMAT = "(G16.8)"
       98046764.
IDL> print, d, FORMAT = "(F20.8)"
   98046763.61700000
IDL> print, d, FORMAT = "(E20.10)"
    9.8046763617E+07

Ken
0
k-bowman (245)
9/11/2003 1:24:59 PM
James Kuyper wrote:
> Reimar Bauer wrote:
> 
>>Hi all,
>>
>>did someone know what here is going on.
>>
>>IDL> d = 98046763.617D
>>IDL> s = string(d)
>>IDL> PRINT,s
>>        98046764.
>>IDL> HELP,s
>>S               STRING    = '       98046764.'
>>
>>Where are the digits ????
> 
> ...
> 
>>Or does it mean I have first to determine the Format of the number and I
>>have to use this information to get the right number.
> 
> 
> If you don't like the default format, you do have to specify the
> particular alternative you wish to use. However, you don't have to be
> explicit:
> 
> IDL> PRINT,string(d,FORMAT='(F)')
> 98046763.6169999990000000
> 
> That's overkill, but at least you didn't lose anything. Coming from a C
> background, I personally prefer:
> 
> IDL> PRINT,string(d,FORMAT='(%"%f")')
> 98046763.617000
> 
> ...

This is exactly what I wanted to have. I missed to test C Formatting codes.

> 
>>This goes right. But my feeling is this is terrible. Because I bet noone
>>takes care on this. What's your feeling?
> 
> 
> My feeling is that you'd lose your bet. Almost everyone who spends much
> time printing floating point numbers ends up sooner or later having to
> override the default formats.

I am not sure because many times it works for float. double makes the 
difference.




Thanks

Reimar






-- 
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
-------------------------------------------------------------------
         a IDL library at ForschungsZentrum Juelich
  http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro.html
===================================================================

0
R.Bauer (610)
9/11/2003 1:35:55 PM
Reply: