[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: significant figures function?
Thanks Ben and Martin! I had already kluged together another solution using a
routine I found using the search engine I found using
http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.html (very handy
tool!) by searching for 'significant' called strnsignif.pro
Wrapping this with a loop and converting back to float did the trick. Less
than perfect, but in the consulting biz, whatever can be found quickly beats
an elegant solution!
Martin Downing wrote:
> "Med Bennett" <firstname.lastname@example.org> wrote in message
> > Has anyone written a function that returns the input value or array with
> > a specified number of significant digits? I have lloked at the various
> > IDL libraries on the web but did not come up with what I'm after.
> > Thanks in advance for any pointers -
> this should do it
> function fix_digits, num, digits
> expon = 1.0
> while num/expon gt 1 do expon = expon * 10
> fix_val = num/expon
> fstring = string(digits+2, digits, format = '("(f",i0.0,".",i0.0,")")')
> reads, string(fix_val, format = fstring), fix_val
> return, fix_val * expon
> > print, fix_digits(!pi, 3)
> Mr. Martin Downing,
> Clinical Research Physicist,
> Orthopaedic RSA Research Centre,
> Woodend Hospital,
> Aberdeen, AB15 6LS.