ruby-units
ruby-units copied to clipboard
Floats are converted to Integer when doing simple conversions
Hello! I realized that while doing some simple conversion and feeding RubyUnits a Float, it'll convert to integer in the end. Here are some samples:
quantity = 97480.0
Unit.new("#{quantity}kg").convert_to("metric-ton") # => 97 tonne
Unit.new("#{quantity.to_f}kg").convert_to("metric-ton") # => 97 tonne
I grep'ed over the code, and I think it is storing the value as Integer (@scalar), but I don't really know if this is the right value to look at.
Any pointers?
Ok, find out a solution: when using a string for initialization, it'll always convert into a Integer (deliberated?), I replaced with:
Unit.new(97480.0, "kg").convert_to("metric-ton") # => 97.48
I can prepare a patch describing those differences for the README, but I think this should be properly documented.