From: "Michael W. Ryder" <_mwryder@...> Date: 2008-05-21T03:50:12+09:00 Subject: Re: Why doesn't Float() work the same as Integer()? ara.t.howard wrote: > On May 19, 2008, at 9:45 PM, Michael W. Ryder wrote: > >> temp = nil >> temp = Float(x) if (Float(x) rescue false) >> if temp == nil >> temp = Integer(x) if (Integer(x) rescue false) >> end >> if temp == nil >> x = 0 >> else >> x = temp >> end >> >> As you can see this is much more code, and that is before I add in >> more code for error handling. > > sort of, you can write this > > x = Float(x) rescue Integer(x) rescue 0 This works fine for me and returns values that I am expecting. Changing it slightly to: x = (Float(x) rescue Integer(x) rescue 0).to_f gives me the Float value I was looking for. I can live with this, just part of learning a new language is learning when something will not work the way you expect and how to work around it. Thank you for the code. I am still learning how to use exceptions. > > but be aware, Float and Integer will handle a nil argument differently. > > > > a @ http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being > better. simply reflect on that. > h.h. the 14th dalai lama > > > >