diff --git a/phpunit.xml b/phpunit.xml index 08f2b37..e7cadf5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,6 +10,11 @@ + + tests + tests/Read + tests/Write + tests/Write diff --git a/src/NumberFormatter.php b/src/NumberFormatter.php index 3fe3e6f..ffe831f 100644 --- a/src/NumberFormatter.php +++ b/src/NumberFormatter.php @@ -19,7 +19,7 @@ public static function format( string $decimalSeparator = ".", string $thousandsSeparator = "" ) { - if ($decimals == null) { + if ($decimals === null) { // Get the current decimal point character according to the locale // This is needed because (string)$number uses the locale's decimal separator $locale = localeconv(); diff --git a/tests/NumberFormatterTest.php b/tests/NumberFormatterTest.php index c195c12..cdf4c23 100644 --- a/tests/NumberFormatterTest.php +++ b/tests/NumberFormatterTest.php @@ -30,6 +30,13 @@ public function formattedNumbersProvider(): array [1.236789, '1.24', 2], [1, '1.00', 2], [1.000, '1', null], + + // An explicit 0 must round to a whole number, not fall back + // to auto-detecting the decimals present in the input + [12.345, '12', 0], + [0.5, '1', 0], + [1.0, '1', 0], + [0.0, '0', 0], ]; } }