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

Home » Public Forums » archive » Re: Specify the degree of accuracy of a floating point number
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: Specify the degree of accuracy of a floating point number [message #52603 is a reply to message #52598] Thu, 22 February 2007 05:05 Go to previous messageGo to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
loknath wrote:
> Hi
> Is there a way to convert a single precision or double precision
> floating point number to an accuracy of specified decimal places? In
> other words, if I want to write 0.268954 or 233.256 to an accuracy of
> 2 decimal places, i.e. 0.27 and 233.26, is there a way to do it?
> Thanks
>

Loknath,

As well as David's suggestion you could look at the format keyword of
string() and print.

e.g.

IDL> number=0.268954
IDL> str=string(number,format='(F0.2)')
IDL> print,str
0.27
IDL> print,number,format='(F0.2)'
0.27

similarly:

IDL> number=233.256
IDL> str=string(number,format='(F0.2)')
IDL> print,str
233.26
IDL> print,number,format='(F0.2)'
233.26

Note that support for F0.N is fairly recent (doesn't work in 6.0, does
work in 6.2 - don't have 6.1 handy to test).

Thanks,

Allan
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Displaying slices using same scaling
Next Topic: READ issue

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

Current Time: Thu Oct 16 20:52:01 PDT 2025

Total time taken to generate the page: 2.63914 seconds