1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Improve quantity resolution

This commit is contained in:
David Bomba 2022-02-26 14:04:05 +11:00
parent 15a9e55fc7
commit 980fcb789f
2 changed files with 65 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}
}