Skip to content

Commit

Permalink
Merge pull request #2 from rb-cohen/master
Browse files Browse the repository at this point in the history
Rounding to decimal places bug
  • Loading branch information
JohnathonKoster authored Oct 7, 2020
2 parents bb5445d + b62e671 commit a892e45
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Numeral.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected function toFixed($number, $decimalPlaces, $optionalDigits = 0)
// Handle the case where there are more decimal places
// than are desired.
if ($currentDecimalLength >= $decimalPlaces) {
$roundedValue = round($number, $decimalPlaces);
$roundedValue = number_format($number, $decimalPlaces, '.', '');

if ($this->stringStartsWith((string) $roundedValue, '-') && +$roundedValue >= 0) {
$roundedValue = mb_substr($roundedValue, 1);
Expand Down
1 change: 1 addition & 0 deletions tests/FormattingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class FormattingTest extends PHPUnit_Framework_TestCase
[100.12345, '0[.]00[000]', '100.12345'],
[100.123456, '0[.]00[000]', '100.12346'],
[100.123453, '0[.]00[000]', '100.12345'],
[0.069999999999993, '0[.]00', '0.07'],


// specified abbreviations
Expand Down

0 comments on commit a892e45

Please sign in to comment.