Skip to content
Snippets Groups Projects
Commit 6a301f13 authored by Ralf Zimmermann's avatar Ralf Zimmermann Committed by Stefan Neufeind
Browse files

[BUGFIX] EXT:form - avoid number reduction in currency filter

Avoid a number reduction each time the filter is applied.
Preserve the decimal places.

Resolves: #69807
Releases: master
Change-Id: I1aed27489ea9a7b7d1f3a3e593803bf075ea25a9
Reviewed-on: https://review.typo3.org/43475


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarBjoern Jacob <bjoern.jacob@tritum.de>
Tested-by: default avatarBjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
parent c8e7f9e3
No related merge requests found
......@@ -89,7 +89,21 @@ class CurrencyFilter extends AbstractFilter implements FilterInterface
*/
public function filter($value)
{
$value = (double) ((string)$value);
$value = str_replace(
array(
$this->thousandSeparator,
$this->decimalsPoint,
),
array(
'',
'.'
),
(string)$value
);
// replace all non numeric characters, decimalPoint and negativ sign
$value = preg_replace("/[^0-9.-]/", "", $value);
$value = (double)$value;
return number_format($value, 2, $this->decimalsPoint, $this->thousandSeparator);
}
}
......@@ -33,29 +33,59 @@ class CurrencyFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
return array(
'1200 => 1.200,00' => array(
1200, // input
'1200', // input
'.', // thousand separator
',', // decimal point
'1.200,00' // expected
),
'0 => 0,00' => array(
0,
'0',
null,
',',
'0,00'
),
'3333.33 => 3,333.33' => array(
3333.33,
'3333.33',
',',
'.',
'3,333.33'
),
'1099.33 => 1 099,33' => array(
1099.33,
'1099.33',
' ',
',',
'1 099,33'
),
'1200,00 => 1.200,00' => array(
'1200,00', // input
'.', // thousand separator
',', // decimal point
'1.200,00' // expected
),
'1.200,00 => 1.200,00' => array(
'1.200,00', // input
'.', // thousand separator
',', // decimal point
'1.200,00' // expected
),
'1.200 => 1.200,00' => array(
'1.200', // input
'.', // thousand separator
',', // decimal point
'1.200,00' // expected
),
'-1 => -1,00' => array(
'-1', // input
'.', // thousand separator
',', // decimal point
'-1,00' // expected
),
'1.200 => 1.200,00' => array(
'1.200', // input
'.', // thousand separator
',', // decimal point
'1.200,00' // expected
),
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment