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.
  • Loading branch information
Naokimi committed Dec 2, 2022
1 parent efe2b3a commit 5483bc1
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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

Expand Down
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
Expand Up @@ -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
Expand Down

0 comments on commit 5483bc1

Please sign in to comment.