Hi guys,
I'm importing data from a csv, I need to cast some values to BigDecimal, and raise an error if they can't be parsed..
From testing, BigDecimal("invalid number") returns a BigDecimal of 0. This would be ok, but kind of messy, except a valid value is 0...
Float("invalid number") acts differently and throws an exception...
My current solution is:
class String
def to_bd
begin
Float(self)
rescue
raise "Unable to parse: #{self}"
end
BigDecimal(self)
end
end
Am I totally missing something?