Re: rounding numbers [message #82924] |
Wed, 23 January 2013 14:29 |
justinclouds
Messages: 25 Registered: December 2012
|
Junior Member |
|
|
On Wednesday, January 23, 2013 3:03:54 PM UTC-7, David Fanning wrote:
> justinclouds writes:
>
>
>
>>
>
>> I would like to be able to round up number of seconds since midnight as follows:
>
>>
>
>> round down 61825 to 61000
>
>> round up 61825 to 62000
>
>>
>
>> Is there an IDL function that does this and what is the syntax?
>
>
>
> IDL> Print, Floor(Float(61825) / 10^3) * 10^3
>
> 61000
>
> IDL> Print, Ceil(Float(61825) / 10^3) * 10^3
>
> 62000
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Thank you. This has been very helpful.
|
|
|
Re: rounding numbers [message #82925 is a reply to message #82924] |
Wed, 23 January 2013 14:03  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
justinclouds writes:
>
> I would like to be able to round up number of seconds since midnight as follows:
>
> round down 61825 to 61000
> round up 61825 to 62000
>
> Is there an IDL function that does this and what is the syntax?
IDL> Print, Floor(Float(61825) / 10^3) * 10^3
61000
IDL> Print, Ceil(Float(61825) / 10^3) * 10^3
62000
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: rounding numbers [message #82926 is a reply to message #82925] |
Wed, 23 January 2013 14:02  |
Phillip Bitzer
Messages: 223 Registered: June 2006
|
Senior Member |
|
|
Since those are the same numbers, I'm not sure when to round up or round down. But I would try something like this:
num = 61825
base = 1000
diff = num MOD base
IF roundUp THEN roundedNum = num + base - diff
IF roundDown THEN roundedNum = num - diff
There are other ways to do it of course, but this would work.
|
|
|