I import data from csv, I need to transfer some values ββto BigDecimal and raise an error if they cannot be analyzed.
From testing, BigDecimal ("invalid number") returns BigDecimal of 0. This would be normal, but sort of randomly, except for a valid value of 0 ...
Float ("invalid number") acts differently and throws an exception ...
My current solution:
class String def to_bd begin Float(self) rescue raise "Unable to parse: #{self}" end BigDecimal(self) end end
Am I missing something at all?
ruby bigdecimal
Michael baldry
source share