diff --git a/lib/money/money.rb b/lib/money/money.rb index a235401462..edc5e9028d 100644 --- a/lib/money/money.rb +++ b/lib/money/money.rb @@ -25,7 +25,11 @@ def fractional if self.class.infinite_precision @fractional else - @fractional.round(0, self.class.rounding_mode).to_i + # If the Money object is created from a serialized YAML string, + # @fractional can end up being set to a Float. We need to ensure + # it is BigDecimal before calling #round with two paramers. + # Float class only provides #round with 0 or 1 parameter. + BigDecimal.new(@fractional.to_s, 0).round(0, self.class.rounding_mode).to_i end end diff --git a/spec/money_spec.rb b/spec/money_spec.rb index aace105399..427320f72d 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -146,6 +146,36 @@ def expectation.fractional m.fractional.should be_a(Fixnum) end end + + context "loading a serialized Money via YAML" do + it "uses BigDecimal when rounding" do + serialized = <