diff --git a/app/Utils/Number.php b/app/Utils/Number.php index f3105ce77958..9d8340640bb3 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -65,6 +65,8 @@ class Number $decimal = $currency->decimal_separator; $precision = $currency->precision; + $precision = 10; + return rtrim(rtrim(number_format($value, $precision, $decimal, $thousand), "0"),$decimal); } diff --git a/tests/Unit/NumberTest.php b/tests/Unit/NumberTest.php index fa12911a8760..a30ebfc0a166 100644 --- a/tests/Unit/NumberTest.php +++ b/tests/Unit/NumberTest.php @@ -78,4 +78,67 @@ class NumberTest extends TestCase // } // }); // } + + public function testRoundingDecimalsTwo() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.05, $currency); + + $this->assertEquals(0.05, $x); + } + + public function testRoundingDecimalsThree() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.005, $currency); + + $this->assertEquals(0.005, $x); + } + + public function testRoundingDecimalsFour() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.0005, $currency); + + $this->assertEquals(0.0005, $x); + } + + public function testRoundingDecimalsFive() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.00005, $currency); + + $this->assertEquals(0.00005, $x); + } + + public function testRoundingDecimalsSix() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.000005, $currency); + + $this->assertEquals(0.000005, $x); + } + + public function testRoundingDecimalsSeven() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.0000005, $currency); + + $this->assertEquals(0.0000005, $x); + } + + public function testRoundingDecimalsEight() + { + $currency = Currency::find(1); + + $x = Number::formatValueNoTrailingZeroes(0.00000005, $currency); + + $this->assertEquals(0.00000005, $x); + } }