[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: significant figures function?



"Ben Tupper" <pemaquidriver@tidewater.net> wrote in message
3A9AEA4B.E6169330@tidewater.net">news:3A9AEA4B.E6169330@tidewater.net...
> You try the following.
>
> ;------start
> ;+
> ; NAME:
> ; ROUNDPV
> ;

hm, I got funny results with this (as i did with my other attempt!)

IDL> print, roundPV( [  0.0002323,34.3434,1234000], 2)
     0.000000     0.000000 1.23400e+006

so I had another think:

function fix_digits, num, digits
 p10 = floor(alog10(abs(num)))
 expo = 10.0d^(digits -1 - p10)
 fix_val = long(num*expo)/expo
 return, fix_val
end

this seems to be fine for all thise who dont care about casting to double
- some one else can reset the type!

IDL> print, fix_digits( [  0.0002323,34.3434,1234000], 2)
   0.00023000000       34.000000       1200000.0


Martin