Skip to content

Commit

Permalink
default to the currency for thousand delimiter when unknown
Browse files Browse the repository at this point in the history
when we're not able to make an educated guess on decimal vs thousand separator, default to using the decimal separator for the currency
  • Loading branch information
elfassy committed Jun 28, 2024
1 parent cb7937f commit 1a100e2
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 @@ -160,11 +160,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 @@ -143,7 +143,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 @@ -252,7 +252,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 @@ -267,7 +267,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 1a100e2

Please sign in to comment.