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

Home » Public Forums » archive » Re: 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
Re: round to x number of decimals within floating point value? [message #74333] Thu, 13 January 2011 16:07 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paulo Penteado writes:

> Is this a non-default finite()? The one I know takes an argument,
> returning whether the elements are finite numbers (not infinity or
> NaN).

Sorry, totally asleep at the wheel. :-(

goodval = where(finite(array) EQ 1, count)

This is the way I usually screen for NANs. Keywords can add
specificity, but this typically works for me. I don't usually
care *why* a value is bad. I just want to work with good values.

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 #74335 is a reply to message #74333] Thu, 13 January 2011 15:55 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 13, 5:35 pm, David Fanning <n...@dfanning.com> wrote:
> Snow53 writes:
>> 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.
>
>     goodval = where(array EQ Finite(), count)
>     if count gt 0 then begin
>        array[gooval] = Float(Round(array[goodval]*1000)/1000.)
>     endif

Is this a non-default finite()? The one I know takes an argument,
returning whether the elements are finite numbers (not infinity or
NaN).
Re: round to x number of decimals within floating point value? [message #74352 is a reply to message #74335] Thu, 13 January 2011 11:40 Go to previous messageGo to next message
Snow53 is currently offline  Snow53
Messages: 32
Registered: July 2010
Member
On Jan 13, 12:35 pm, David Fanning <n...@dfanning.com> wrote:
> Snow53 writes:
>> 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.
>
>     goodval = where(array EQ Finite(), count)
>     if count gt 0 then begin
>        array[gooval] = Float(Round(array[goodval]*1000)/1000.)
>     endif
>
> 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.")

Sweet! Thanks :)
Re: round to x number of decimals within floating point value? [message #74353 is a reply to message #74352] Thu, 13 January 2011 11:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Snow53 writes:

> 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.

goodval = where(array EQ Finite(), count)
if count gt 0 then begin
array[gooval] = Float(Round(array[goodval]*1000)/1000.)
endif

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 #74442 is a reply to message #74333] Fri, 14 January 2011 07:16 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <MPG.279941936212ce0e98992d@news.giganews.com>,
David Fanning <news@dfanning.com> wrote:

> goodval = where(finite(array) EQ 1, count)

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.

Cheers, Ken
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Temp variables are checked out
Next Topic: Re: Temp variables are checked out

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

Current Time: Wed Oct 08 15:17:00 PDT 2025

Total time taken to generate the page: 0.00654 seconds