Skip to content

Commit

Permalink
Merge pull request #327 from Shopify/thousand-delimiter-fuzzy-parser
Browse files Browse the repository at this point in the history
default to the currency for thousand delimiter when unknown
  • Loading branch information
elfassy authored Aug 19, 2024
2 parents e5fe72c + df6e519 commit 18b9fe4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
5 changes: 0 additions & 5 deletions lib/money/parser/fuzzy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ def last_digits_decimals?(digits, marks, currency)
return true
end

# legacy support for 1.000 USD
if digits.last.size == 3 && digits.first.size <= 3 && currency.minor_units < 3
return false
end

# The last mark matches the one used by the provided currency to delimiter decimals
currency.decimal_mark == last_mark
end
Expand Down
2 changes: 1 addition & 1 deletion spec/parser/accounting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

it "parses thousands amount" do
Money.with_currency(Money::NULL_CURRENCY) do
expect(@parser.parse("1.000")).to eq(Money.new(1000.00))
expect(@parser.parse("1.000")).to eq(Money.new(1.00))
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/parser/fuzzy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
end

it "parses no currency amount" do
expect(@parser.parse("1.000", Money::NULL_CURRENCY)).to eq(Money.new(1000, Money::NULL_CURRENCY))
expect(@parser.parse("1.000", Money::NULL_CURRENCY)).to eq(Money.new(1, Money::NULL_CURRENCY))
end

it "parses amount with more than 3 decimals correctly" do
Expand Down Expand Up @@ -246,7 +246,7 @@
describe "no decimal currency" do
it "parses thousands correctly" do
expect(@parser.parse("1,111", "JPY")).to eq(Money.new(1_111, 'JPY'))
expect(@parser.parse("1.111", "JPY")).to eq(Money.new(1_111, 'JPY'))
expect(@parser.parse("1.111", "JPY")).to eq(Money.new(1, 'JPY'))
expect(@parser.parse("1 111", "JPY")).to eq(Money.new(1_111, 'JPY'))
expect(@parser.parse("1111,111", "JPY")).to eq(Money.new(1_111_111, 'JPY'))
end
Expand All @@ -261,7 +261,7 @@
describe "two decimal currency" do
it "parses thousands correctly" do
expect(@parser.parse("1,111", "USD")).to eq(Money.new(1_111, 'USD'))
expect(@parser.parse("1.111", "USD")).to eq(Money.new(1_111, 'USD'))
expect(@parser.parse("1.111", "USD")).to eq(Money.new(1.11, 'USD'))
expect(@parser.parse("1 111", "USD")).to eq(Money.new(1_111, 'USD'))
expect(@parser.parse("1111,111", "USD")).to eq(Money.new(1_111_111, 'USD'))
end
Expand Down

0 comments on commit 18b9fe4

Please sign in to comment.