On Fri, May 15, 2009 at 6:57 PM, Max Williams <toastkid.williams / gmail.com> wrote: > I have a requirement where i need to display (ie convert to a string) > all digits to 3 significant figures. not the same as 3 decimal places) > > eg > > 3 => "23" > 6759 => "26,800" > 0.546 => "10.5" > 332332 => "3,330,000" > .766 => "0.766" > .00000766 => "0.00000766" > > Can anyone show me a neat way to do this? ¨Â§ä èáöå ôèïõçèôèáô ôèåòå§> be a method for it already but i can't find one. > > thanks! > max > -- > Posted via http://www.ruby-forum.com/. > > At frirst sight and testing with the data you have given, the following pretty much seems to do the trick: x.to_s.sub( /(\.0*\d{0,3}).*/, '\1' ) Did I overlook any edge cases? HTH R.