mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fix #1059
This commit is contained in:
@@ -66,6 +66,18 @@ class Amount implements ConverterInterface
|
|||||||
Log::debug(sprintf('Alternate search resulted in "%s" for decimal sign.', $decimal));
|
Log::debug(sprintf('Alternate search resulted in "%s" for decimal sign.', $decimal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decimal character still null? Search from the left for '.',',' or ' '.
|
||||||
|
if (is_null($decimal)) {
|
||||||
|
Log::debug('Decimal is still NULL, probably number with >2 decimals. Search for a dot.');
|
||||||
|
$res = strrpos($value, '.');
|
||||||
|
if (!($res === false)) {
|
||||||
|
// blandly assume this is the one.
|
||||||
|
Log::debug(sprintf('Searched from the left for "." in amount "%s", assume this is the decimal sign.', $value));
|
||||||
|
$decimal = '.';
|
||||||
|
}
|
||||||
|
unset($options, $res, $candidate);
|
||||||
|
}
|
||||||
|
|
||||||
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
|
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
|
||||||
if ('.' === $decimal) {
|
if ('.' === $decimal) {
|
||||||
$search = [',', ' '];
|
$search = [',', ' '];
|
||||||
|
@@ -61,6 +61,7 @@ class AmountTest extends TestCase
|
|||||||
'1,234' => '1234',
|
'1,234' => '1234',
|
||||||
'1,234.5' => '1234.5',
|
'1,234.5' => '1234.5',
|
||||||
'1,234.56' => '1234.56',
|
'1,234.56' => '1234.56',
|
||||||
|
'123,456,789' => '123456789',
|
||||||
'0,0' => '0',
|
'0,0' => '0',
|
||||||
'0,1' => '0.1',
|
'0,1' => '0.1',
|
||||||
',2' => '0.2',
|
',2' => '0.2',
|
||||||
@@ -77,9 +78,67 @@ class AmountTest extends TestCase
|
|||||||
'1234,56' => '1234.56',
|
'1234,56' => '1234.56',
|
||||||
'1 234,5' => '1234.5',
|
'1 234,5' => '1234.5',
|
||||||
'1 234,56' => '1234.56',
|
'1 234,56' => '1234.56',
|
||||||
'1.234' => '1234',
|
'1.234' => '1.234', // will no longer match as 1234, but as 1.234
|
||||||
'1.234,5' => '1234.5',
|
'1.234,5' => '1234.5',
|
||||||
'1.234,56' => '1234.56',
|
'1.234,56' => '1234.56',
|
||||||
|
// many decimals
|
||||||
|
'2.00' => '2',
|
||||||
|
'3.000' => '3',
|
||||||
|
'4.0000' => '4',
|
||||||
|
'5.000' => '5',
|
||||||
|
'6.0000' => '6',
|
||||||
|
'7.200' => '7.2',
|
||||||
|
'8.2000' => '8.2',
|
||||||
|
'9.330' => '9.33',
|
||||||
|
'10.3300' => '10.33',
|
||||||
|
'11.444' => '11.444',
|
||||||
|
'12.4440' => '12.444',
|
||||||
|
'13.5555' => '13.5555',
|
||||||
|
'14.45678' => '14.45678',
|
||||||
|
'15.456789' => '15.456789',
|
||||||
|
'16.4567898' => '16.4567898',
|
||||||
|
'17.34567898' => '17.34567898',
|
||||||
|
'18.134567898' => '18.134567898',
|
||||||
|
'19.1634567898' => '19.1634567898',
|
||||||
|
'20.16334567898' => '20.16334567898',
|
||||||
|
'21.16364567898' => '21.16364567898',
|
||||||
|
'22.163644567898' => '22.163644567898',
|
||||||
|
// many decimals, mixed, large numbers
|
||||||
|
'63522.00' => '63522',
|
||||||
|
'63523.000' => '63523',
|
||||||
|
'63524.0000' => '63524',
|
||||||
|
'63525.000' => '63525',
|
||||||
|
'63526.0000' => '63526',
|
||||||
|
'63527.200' => '63527.2',
|
||||||
|
'63528.2000' => '63528.2',
|
||||||
|
'63529.330' => '63529.33',
|
||||||
|
'635210.3300' => '635210.33',
|
||||||
|
'635211.444' => '635211.444',
|
||||||
|
'635212.4440' => '635212.444',
|
||||||
|
'635213.5555' => '635213.5555',
|
||||||
|
'635214.45678' => '635214.45678',
|
||||||
|
'635215.456789' => '635215.456789',
|
||||||
|
'635216.4567898' => '635216.4567898',
|
||||||
|
'635217.34567898' => '635217.34567898',
|
||||||
|
'635218.134567898' => '635218.134567898',
|
||||||
|
'635219.1634567898' => '635219.1634567898',
|
||||||
|
'635220.16334567898' => '635220.16334567898',
|
||||||
|
'635221.16364567898' => '635221.16364567898',
|
||||||
|
'635222.163644567898' => '635222.163644567898',
|
||||||
|
// many decimals, mixed, also mixed thousands separators
|
||||||
|
'63 522.00' => '63522',
|
||||||
|
'63 523.000' => '63523',
|
||||||
|
'63,524.0000' => '63524',
|
||||||
|
'63 525.000' => '63525',
|
||||||
|
'63,526.0000' => '63526',
|
||||||
|
'63 527.200' => '63527.2',
|
||||||
|
'63 528.2000' => '63528.2',
|
||||||
|
'63 529.330' => '63529.33',
|
||||||
|
'63,5210.3300' => '635210.33',
|
||||||
|
'63,5211.444' => '635211.444',
|
||||||
|
'63 5212.4440' => '635212.444',
|
||||||
|
'163 5219.1634567898' => '1635219.1634567898',
|
||||||
|
'444 163 5219.1634567898' => '4441635219.1634567898',
|
||||||
];
|
];
|
||||||
foreach ($values as $value => $expected) {
|
foreach ($values as $value => $expected) {
|
||||||
$converter = new Amount;
|
$converter = new Amount;
|
||||||
|
Reference in New Issue
Block a user