Fix fractional cents appearing on sales tax report totals

This commit is contained in:
Rohan Mitchell
2015-01-13 14:47:13 +11:00
parent ec22f4c09f
commit dd61034908
2 changed files with 13 additions and 0 deletions

View File

@@ -42,6 +42,10 @@ module OpenFoodNetwork
end
end
totals.each_pair do |k, v|
totals[k] = totals[k].round(2)
end
totals
end

View File

@@ -21,6 +21,15 @@ module OpenFoodNetwork
totals[:items_total].should == 36
end
context "when floating point math would result in fractional cents" do
let(:li1) { double(:line_item, quantity: 1, amount: 0.11) }
let(:li2) { double(:line_item, quantity: 2, amount: 0.12) }
it "rounds to the nearest cent" do
totals[:items_total].should == 0.23
end
end
it "calculates the taxable total price" do
totals[:taxable_total].should == 36
end