From: jason joo Date: 2010-08-11T14:03:30+09:00 Subject: Re: Hel;p with Tip Calculator --000e0cd3320895ceca048d8529cc Content-Type: text/plain; charset=ISO-8859-1 aha, i forgot positive number and dot. then the regular expression should be /([\-+]?\d*[.]?\d*)/ eg if input_string =~ /([\-+]?\d*[.]?\d*)/ input_string = $1 else #have no number part input_string = 0 end 9 => "9" -9 => "-9" -9.098 => "-9.098" 2010/8/11 Hassan Schroeder > On Tue, Aug 10, 2010 at 6:38 PM, jason joo wrote: > > or just > >>> input_string.to_s.gsub(/\D/,'') > > for number format permitted > > Depending on what your actual numeric use case is :-) > > $ irb > >> input = 9 > => 9 > >> input.to_s.gsub(/\D/,'') > => "9" > >> input = 9.095 > => 9.095 > >> input.to_s.gsub(/\D/,'') > => "9095" > >> > > -- > Hassan Schroeder ------------------------ hassan.schroeder@gmail.com > twitter: @hassan > > --000e0cd3320895ceca048d8529cc--