mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Improve amount conversion code.
This commit is contained in:
@@ -98,8 +98,31 @@ class Amount implements ConverterInterface
|
||||
$value = str_replace($search, '', $value);
|
||||
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $original, $value));
|
||||
}
|
||||
if ($value{0} === '.') {
|
||||
$value = '0' . $value;
|
||||
}
|
||||
|
||||
return number_format(round((float)$value, 12), 12, '.', '');
|
||||
if (is_numeric($value)) {
|
||||
Log::debug(sprintf('Final NUMERIC value is: "%s"', $value));
|
||||
|
||||
return $value;
|
||||
}
|
||||
Log::debug(sprintf('Final value is: "%s"', $value));
|
||||
$formatted = sprintf('%01.12f', $value);
|
||||
Log::debug(sprintf('Is formatted to : "%s"', $formatted));
|
||||
|
||||
return $formatted;
|
||||
}
|
||||
|
||||
private function bcround($number, $scale = 0)
|
||||
{
|
||||
$fix = "5";
|
||||
for ($i = 0; $i < $scale; $i++) {
|
||||
$fix = "0$fix";
|
||||
}
|
||||
$number = bcadd($number, "0.$fix", $scale + 1);
|
||||
|
||||
return bcdiv($number, "1.0", $scale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user