[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: significant figures function?
"Ben Tupper" <firstname.lastname@example.org> wrote in message
> You try the following.
> ; 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
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