mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 12:34:37 -04:00
Fixes for float parsing for csv importrs
This commit is contained in:
parent
caa5b4b430
commit
a52025dabd
@ -316,7 +316,7 @@ class BaseTransformer
|
|||||||
{
|
{
|
||||||
if (array_key_exists($field, $data)) {
|
if (array_key_exists($field, $data)) {
|
||||||
//$number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
|
//$number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
|
||||||
return Number::parseStringFloat($data[$field]);
|
return Number::parseFloat($data[$field]);
|
||||||
} else {
|
} else {
|
||||||
//$number = 0;
|
//$number = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@ -334,7 +334,7 @@ class BaseTransformer
|
|||||||
public function getFloatOrOne($data, $field)
|
public function getFloatOrOne($data, $field)
|
||||||
{
|
{
|
||||||
if (array_key_exists($field, $data)) {
|
if (array_key_exists($field, $data)) {
|
||||||
return Number::parseStringFloat($data[$field]) > 0 ? Number::parseStringFloat($data[$field]) : 1;
|
return Number::parseFloat($data[$field]) > 0 ? Number::parseFloat($data[$field]) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -20,6 +20,34 @@ use Tests\TestCase;
|
|||||||
*/
|
*/
|
||||||
class NumberTest extends TestCase
|
class NumberTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function testConvertDecimalCommaFloats()
|
||||||
|
{
|
||||||
|
$value = '22,00';
|
||||||
|
|
||||||
|
$res = Number::parseFloat($value);
|
||||||
|
|
||||||
|
$this->assertEquals(22.0, $res);
|
||||||
|
|
||||||
|
$value = '22.00';
|
||||||
|
|
||||||
|
$res = Number::parseFloat($value);
|
||||||
|
|
||||||
|
$this->assertEquals(22.0, $res);
|
||||||
|
|
||||||
|
$value = '1,000.00';
|
||||||
|
|
||||||
|
$res = Number::parseFloat($value);
|
||||||
|
|
||||||
|
$this->assertEquals(1000.0, $res);
|
||||||
|
|
||||||
|
$value = '1.000,00';
|
||||||
|
|
||||||
|
$res = Number::parseFloat($value);
|
||||||
|
|
||||||
|
$this->assertEquals(1000.0, $res);
|
||||||
|
|
||||||
|
}
|
||||||
public function testFloatPrecision()
|
public function testFloatPrecision()
|
||||||
{
|
{
|
||||||
$value = 1.1;
|
$value = 1.1;
|
||||||
|
@ -20,7 +20,6 @@ use Tests\TestCase;
|
|||||||
|
|
||||||
class WithTypeHelpersTest extends TestCase
|
class WithTypeHelpersTest extends TestCase
|
||||||
{
|
{
|
||||||
use DatabaseMigrations;
|
|
||||||
|
|
||||||
public function testIsImageHelper(): void
|
public function testIsImageHelper(): void
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user