diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc3d074..0168cc29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Parser/IntlMoneyParser.php b/src/Parser/IntlMoneyParser.php index 36a01949..0ac403e4 100644 --- a/src/Parser/IntlMoneyParser.php +++ b/src/Parser/IntlMoneyParser.php @@ -85,6 +85,10 @@ public function parse($money, $forceCurrency = null) $decimal = ltrim($decimal, '0'); } + if ('' === $decimal) { + $decimal = '0'; + } + return new Money($decimal, $currency); } } diff --git a/tests/Parser/BitcoinMoneyParserTest.php b/tests/Parser/BitcoinMoneyParserTest.php index 288ecd2e..add0d390 100644 --- a/tests/Parser/BitcoinMoneyParserTest.php +++ b/tests/Parser/BitcoinMoneyParserTest.php @@ -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], diff --git a/tests/Parser/DecimalMoneyParserTest.php b/tests/Parser/DecimalMoneyParserTest.php index 22cdc16c..76f5eab7 100644 --- a/tests/Parser/DecimalMoneyParserTest.php +++ b/tests/Parser/DecimalMoneyParserTest.php @@ -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], diff --git a/tests/Parser/IntlMoneyParserTest.php b/tests/Parser/IntlMoneyParserTest.php index 33b94fe8..c2d5935b 100644 --- a/tests/Parser/IntlMoneyParserTest.php +++ b/tests/Parser/IntlMoneyParserTest.php @@ -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],