mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for parse float
This commit is contained in:
parent
2f8f9ffce8
commit
6445e518dc
@ -315,14 +315,11 @@ class BaseTransformer
|
||||
public function getFloat($data, $field)
|
||||
{
|
||||
if (array_key_exists($field, $data)) {
|
||||
//$number = preg_replace('/[^0-9-.]+/', '', $data[$field]);
|
||||
return Number::parseFloat($data[$field]);
|
||||
} else {
|
||||
//$number = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return Number::parseFloat($number);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,6 +95,14 @@ class Number
|
||||
*/
|
||||
public static function parseFloat($value)
|
||||
{
|
||||
if(!$value)
|
||||
return 0;
|
||||
|
||||
$multiplier = false;
|
||||
|
||||
if(substr($value, 0,1) == '-')
|
||||
$multiplier = -1;
|
||||
|
||||
// convert "," to "."
|
||||
$s = str_replace(',', '.', $value);
|
||||
|
||||
@ -108,7 +116,9 @@ class Number
|
||||
// remove all separators from first part and keep the end
|
||||
$s = str_replace('.', '', substr($s, 0, -3)).substr($s, -3);
|
||||
|
||||
// return float
|
||||
if($multiplier)
|
||||
$s = floatval($s)*-1;
|
||||
|
||||
return (float) $s;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user