Joel VanderWerf
7/1/2008 10:15:00 PM
Iñaki Baz Castillo wrote:
> Hi, I want to convert a string to a Float value:
>
> irb> "1.5".to_f
> => 1.5
>
> But if I do:
>
> irb> "1".to_f
> => 1.0
>
> I get '1.0' instead of just '1'. Is not possible to just get '1' in this case?
Well, you could do this:
a = ["1", "1.5"].map do |x|
Float x # validate
eval x
end
p a
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407