I have an Excel column containing part numbers. Here is a sample
As you can see, it can be many differ
Numeric values are returned as type :float
def convert_cell(cell) if cell.is_a?(Float) i = cell.to_i cell == i.to_f ? i : cell else cell end end convert_cell("foobar") # => "foobar" convert_cell(123) # => 123 convert_cell(123.4) # => 123.4