Skip to content

Commit

Permalink
fix parsing zero in intl parser, test other parsers (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Mar 22, 2017
1 parent ccd4c81 commit 295c513
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Parsing empty strings and number starting or ending with a decimal point for DecimalMoneyParser
- Parsing zero for DecimalMoneyParser
- Multiplying and dividing with a locale that use commas as separator

## 3.0.2 - 2017-03-11
Expand Down
4 changes: 4 additions & 0 deletions src/Parser/IntlMoneyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function parse($money, $forceCurrency = null)
$decimal = ltrim($decimal, '0');
}

if ('' === $decimal) {
$decimal = '0';
}

return new Money($decimal, $currency);
}
}
1 change: 1 addition & 0 deletions tests/Parser/BitcoinMoneyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function bitcoinExamples()
["\0xC9\0x831000.0", 100000],
["\0xC9\0x831000.00", 100000],
["\0xC9\0x830.01", 1],
["\0xC9\0x830.00", 0],
["\0xC9\0x831", 100],
["-\0xC9\0x831000", -100000],
["-\0xC9\0x831000.0", -100000],
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/DecimalMoneyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function formattedMoneyExamples()
['1000.0', 'USD', 2, 100000],
['1000', 'USD', 2, 100000],
['0.01', 'USD', 2, 1],
['0.00', 'USD', 2, 0],
['1', 'USD', 2, 100],
['-1000.50', 'USD', 2, -100050],
['-1000.00', 'USD', 2, -100000],
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/IntlMoneyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function formattedMoneyExamples()
['$1000.0', 100000],
['$1000.00', 100000],
['$0.01', 1],
['$0.00', 0],
['$1', 100],
['-$1000', -100000],
['-$1000.0', -100000],
Expand Down

0 comments on commit 295c513

Please sign in to comment.