Skip to content

Commit

Permalink
Allow parsing of single digit amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Sep 2, 2019
1 parent c1930a0 commit 0898628
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog for Money v4.2.1

This is the changelog for Money v4.2.1 released on September 2nd, 2019. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/cldr/tags)

### Bug Fixes

* Fixes parsing of money amount that have a single digit amount. Closes #107. Thanks to @njwest

# Changelog for Money v4.2.0

This is the changelog for Money v4.2.0 released on 21 August, 2019. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/cldr/tags)
Expand Down
2 changes: 1 addition & 1 deletion lib/money.ex
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ defmodule Money do
@grouping_chars ",،٫、︐︑﹐﹑,、"
@decimal_chars ".․。︒﹒.。"
@currency "[^0-9#{@grouping_chars}#{@decimal_chars}]+"
@amount "[0-9][0-9#{@grouping_chars}#{@decimal_chars}]+"
@amount "[0-9][0-9#{@grouping_chars}#{@decimal_chars}]*"
@regex Regex.compile!("^(?<cb>#{@currency})?(?<amount>#{@amount})?(?<ca>#{@currency})?$", "u")

@doc false
Expand Down
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Money.Mixfile do
use Mix.Project

@version "4.2.0"
@version "4.2.1"

def project do
[
Expand Down
6 changes: 6 additions & 0 deletions test/money_parse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ defmodule MoneyTest.Parse do
assert Money.parse("USD 100.00") == Money.new(:USD, "100.00")
end

test "parses with a single digit amount" do
assert Money.parse("USD 1") == Money.new(:USD, 1)
assert Money.parse("USD1") == Money.new(:USD, 1)
assert Money.parse("USD9") == Money.new(:USD, 9)
end

test "parses with currency code out back" do
assert Money.parse("100 USD") == Money.new(:USD, 100)
assert Money.parse("100USD") == Money.new(:USD, 100)
Expand Down

0 comments on commit 0898628

Please sign in to comment.