mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 08:34:36 -04:00
Fixes for tax floats with precision greater than 2
This commit is contained in:
parent
e0c1d0d29e
commit
f014ced0d5
@ -152,6 +152,12 @@ class BaseTransformer
|
|||||||
return Number::parseFloat($number);
|
return Number::parseFloat($number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFloatWithSamePrecision($data, $field)
|
||||||
|
{
|
||||||
|
$precision = (int) strpos(strrev($data[$field]), ".");
|
||||||
|
|
||||||
|
return round($data[$field], $precision);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
*
|
*
|
||||||
|
@ -39,11 +39,11 @@ class InvoiceTransformer extends BaseTransformer
|
|||||||
'is_sent' => $this->getString($data, 'invoice.is_sent'),
|
'is_sent' => $this->getString($data, 'invoice.is_sent'),
|
||||||
'private_notes' => $this->getString($data, 'invoice.private_notes'),
|
'private_notes' => $this->getString($data, 'invoice.private_notes'),
|
||||||
'tax_name1' => $this->getString($data, 'invoice.tax_name1'),
|
'tax_name1' => $this->getString($data, 'invoice.tax_name1'),
|
||||||
'tax_rate1' => $this->getFloat($data, 'invoice.tax_rate1'),
|
'tax_rate1' => $this->getFloatWithSamePrecision($data, 'invoice.tax_rate1'),
|
||||||
'tax_name2' => $this->getString($data, 'invoice.tax_name2'),
|
'tax_name2' => $this->getString($data, 'invoice.tax_name2'),
|
||||||
'tax_rate2' => $this->getFloat($data, 'invoice.tax_rate2'),
|
'tax_rate2' => $this->getFloatWithSamePrecision($data, 'invoice.tax_rate2'),
|
||||||
'tax_name3' => $this->getString($data, 'invoice.tax_name3'),
|
'tax_name3' => $this->getString($data, 'invoice.tax_name3'),
|
||||||
'tax_rate3' => $this->getFloat($data, 'invoice.tax_rate3'),
|
'tax_rate3' => $this->getFloatWithSamePrecision($data, 'invoice.tax_rate3'),
|
||||||
'custom_value1' => $this->getString($data, 'invoice.custom_value1'),
|
'custom_value1' => $this->getString($data, 'invoice.custom_value1'),
|
||||||
'custom_value2' => $this->getString($data, 'invoice.custom_value2'),
|
'custom_value2' => $this->getString($data, 'invoice.custom_value2'),
|
||||||
'custom_value3' => $this->getString($data, 'invoice.custom_value3'),
|
'custom_value3' => $this->getString($data, 'invoice.custom_value3'),
|
||||||
|
@ -21,6 +21,53 @@ use Tests\TestCase;
|
|||||||
*/
|
*/
|
||||||
class NumberTest extends TestCase
|
class NumberTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function testFloatPrecision()
|
||||||
|
{
|
||||||
|
$value = 1.1;
|
||||||
|
|
||||||
|
$precision = (int) strpos(strrev($value), ".");
|
||||||
|
|
||||||
|
$result = round($value, $precision);
|
||||||
|
|
||||||
|
$this->assertEquals(1.1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFloatPrecision1()
|
||||||
|
{
|
||||||
|
$value = "1.1";
|
||||||
|
|
||||||
|
$precision = (int) strpos(strrev($value), ".");
|
||||||
|
|
||||||
|
$result = round($value, $precision);
|
||||||
|
|
||||||
|
$this->assertEquals(1.1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFloatPrecision2()
|
||||||
|
{
|
||||||
|
$value = 9.975;
|
||||||
|
|
||||||
|
$precision = (int) strpos(strrev($value), ".");
|
||||||
|
|
||||||
|
$result = round($value, $precision);
|
||||||
|
|
||||||
|
$this->assertEquals(9.975, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFloatPrecision3()
|
||||||
|
{
|
||||||
|
$value = "9.975";
|
||||||
|
|
||||||
|
$precision = (int) strpos(strrev($value), ".");
|
||||||
|
|
||||||
|
$result = round($value, $precision);
|
||||||
|
|
||||||
|
$this->assertEquals(9.975, $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRoundingThreeLow()
|
public function testRoundingThreeLow()
|
||||||
{
|
{
|
||||||
$rounded = Number::roundValue(3.144444444444, 3);
|
$rounded = Number::roundValue(3.144444444444, 3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user