From: Chris Morris Date: 2002-03-28T12:55:42+09:00 Subject: RE: parsing strings into numbers > Kinda messy, but you can do > > result = Integer(value) rescue Float(value) > > or > > result = Integer(value) rescue Float(value) rescue nil Cool ... this is actually much better than the road I was going down: if (value =~ /[\d-]+/) && !(value =~ /[.]/) && !(value =~ /[^\d-]/) value.to_i elsif (value =~ /[\d.-]+/) && !(value =~ /[^\d.-]/) value.to_f else value end ... and this doesn't take into account any of the weird cases: 4e5 Oxaabb ... etc. (Also, very cool inline error handling. Ruby continues to rock and amaze). Chris