|
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   |
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 #92475 is a reply to message #92463] |
Wed, 23 December 2015 07:57  |
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
|
|
|