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

Home » Public Forums » archive » round to x number of decimals within floating point value?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
round to x number of decimals within floating point value? [message #74355] Thu, 13 January 2011 11:29 Go to next message
Snow53 is currently offline  Snow53
Messages: 32
Registered: July 2010
Member
I need to round the values within a file to three decimal places. For
example, 0.00053335 would become 0.001.
I also have many NaNs within the file.

Any suggestions?

Thanks!
Re: round to x number of decimals within floating point value? [message #74441 is a reply to message #74355] Fri, 14 January 2011 07:33 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth P. Bowman writes:

> The equality test is unnecessary, so you can write
>
> goodval = where(finite(array), count)
>
> to find the good values and
>
> badval = where(~finite(array), count)
>
> to find the bad values. And of course you can do both
> with a single WHERE and appropriate keywords.

Yes, of course, but with the usual quibbles about
making your programs so cryptic newbies can't figure
them out. :-)

In this case, if you know what "finite" means, you
are good to go.

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.")
Re: round to x number of decimals within floating point value? [message #92463 is a reply to message #74355] Tue, 22 December 2015 13:17 Go to previous messageGo to next message
omar ali is currently offline  omar ali
Messages: 13
Registered: December 2015
Junior Member
بتاريخ الخميس، 13 يناير، 2011 8:29:29 م UTC+1، كتب Snow53:
> I need to round the values within a file to three decimal places. For
> example, 0.00053335 would become 0.001.
> I also have many NaNs within the file.
>
> Any suggestions?
>
> Thanks!

Hi there,
I have gone through the messages and i wonder there is a solution to conver 0.00053335 to 0.001. Indeed, i have a number (0.2345678)and i want it to be with 2 digits after the decimal

Thanks in advance
Re: round to x number of decimals within floating point value? [message #92475 is a reply to message #92463] Wed, 23 December 2015 07:57 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Tuesday, December 22, 2015 at 4:17:06 PM UTC-5, omar ali wrote:
> بتاريخ الخميس، 13 يناير، 2011 8:29:29 م UTC+1، كتب Snow53:
>> I need to round the values within a file to three decimal places. For
>> example, 0.00053335 would become 0.001.
>> I also have many NaNs within the file.
>>
>> Any suggestions?
>>
>> Thanks!
>
> Hi there,
> I have gone through the messages and i wonder there is a solution to conver 0.00053335 to 0.001. Indeed, i have a number (0.2345678)and i want it to be with 2 digits after the decimal

David's solution from four years ago is still a good one...
IDL> a = 0.2345678d
IDL> print, round(a*100)/100.0d
0.23000000
Or if you just care about the printed version,
IDL> print, a, format='(D0.2)'
0.23
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: It's about time
Next Topic: GDAL spawn library conflict

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

Current Time: Wed Oct 08 07:25:22 PDT 2025

Total time taken to generate the page: 0.00695 seconds