diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 3920773d06..d5b69011d2 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -42,6 +42,10 @@ module OpenFoodNetwork end end + totals.each_pair do |k, v| + totals[k] = totals[k].round(2) + end + totals end diff --git a/spec/lib/open_food_network/sales_tax_report_spec.rb b/spec/lib/open_food_network/sales_tax_report_spec.rb index cf00f650ff..043eac6ae7 100644 --- a/spec/lib/open_food_network/sales_tax_report_spec.rb +++ b/spec/lib/open_food_network/sales_tax_report_spec.rb @@ -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