Skip to content

Commit

Permalink
Remove trailing zeroes in tax amount
Browse files Browse the repository at this point in the history
NumberToPercentageConverter defaults to a precision of 3, leading to
displays of VAT amount like '21.000%' on the cart's label, which doesn't
look good. Using `precision: nil` will keep the default precision of the
number.

(cherry picked from commit 5483bc1)
Naokimi committed Dec 7, 2022

Verified

This commit was signed with the committer’s verified signature.
Mamaduka George Mamadashvili
1 parent 5f310b5 commit 7a88734
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/spec/features/admin/orders/adjustments_spec.rb
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
context "admin managing adjustments" do
it "should display the correct values for existing order adjustments" do
within first('table tr', text: 'Tax') do
expect(column_text(2)).to match(/TaxCategory - \d+ 20\.000%/)
expect(column_text(2)).to match(/TaxCategory - \d+ 20\.0%/)
expect(column_text(3)).to eq("$2.00")
end
end
3 changes: 2 additions & 1 deletion core/app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
@@ -113,7 +113,8 @@ def adjustment_label(amount)
def amount_for_adjustment_label
ActiveSupport::NumberHelper::NumberToPercentageConverter.convert(
amount * 100,
locale: I18n.locale
locale: I18n.locale,
precision: nil
)
end

2 changes: 1 addition & 1 deletion core/spec/models/spree/tax_calculator/default_spec.rb
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@
expect(line_item_tax.amount).to eq 1
expect(line_item_tax.included_in_price).to be false
expect(line_item_tax.tax_rate).to eq book_tax_rate
expect(line_item_tax.label).to eq "New York Sales Tax 5.000%"
expect(line_item_tax.label).to eq "New York Sales Tax 5.0%"
end

it "has tax information for the shipments" do

0 comments on commit 7a88734

Please sign in to comment.