Thanks rob!
I combined that with the rails helper 'number_with_delimiter, and it
works great:
def number_to_n_significant_digits(number, n = 3)
("%f"%[("%.#{n}g"%number).to_f]).sub(/\.?0*\z/,'')
end
#in my other method
number_with_delimiter(number_to_n_significant_digits(number))
I don't think the 0.0000008 instead of 0.000000766 case will be a
problem.
My next quest is to work out what's going on in your code snippet.
I can see that the sub at the end removes trailing zeros, right?
And the first part looks like some oldschool c-style string
substitution, time to pull out the pickaxe :)
thanks again!
max
--
Posted via http://www.ruby-forum.com/.