Skip to content

Commit

Permalink
fix 2234
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 26, 2024
1 parent 1133dc8 commit b9eb989
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Persistence/Ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function _typecastSaveField(Field $field, $value): ?string
break;
case 'atk4_money':
$value = parent::_typecastLoadField($field, $value);
$valueDecimals = strlen(preg_replace('~^[^.]$|^.+\.|0+$~s', '', number_format($value, max(0, 11 - (int) log10($value)), '.', '')));
$valueDecimals = strlen(preg_replace('~^[^.]$|^.+\.|0+$~s', '', number_format($value, max(0, 11 - (int) log10(abs($value))), '.', '')));
$value = ($this->currency ? $this->currency . ' ' : '')
. number_format($value, max($this->currencyDecimals, $valueDecimals), $this->decimalSeparator, $this->thousandsSeparator);
$value = str_replace(' ', "\u{00a0}" /* Unicode NBSP */, $value);
Expand Down
3 changes: 3 additions & 0 deletions tests/PersistenceUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ public static function provideTypecastBidirectionalCases(): iterable
yield [['currencyDecimals' => 1], ['type' => 'atk4_money'], 1.1, $fixSpaceToNbspFx('€ 1.1')];
yield [['currencyDecimals' => 4], ['type' => 'atk4_money'], 1.102, $fixSpaceToNbspFx('€ 1.1020')];
yield [[], ['type' => 'atk4_money'], 1_234_056_789.1, $fixSpaceToNbspFx('€ 1 234 056 789.10')];
yield [[], ['type' => 'atk4_money'], -1_234_056_789.1, $fixSpaceToNbspFx('€ -1 234 056 789.10')];
yield [[], ['type' => 'atk4_money'], 234_056_789.101, $fixSpaceToNbspFx('€ 234 056 789.101')];
yield [[], ['type' => 'atk4_money'], -234_056_789.101, $fixSpaceToNbspFx('€ -234 056 789.101')];
yield [['decimalSeparator' => ','], ['type' => 'atk4_money'], 1.0, $fixSpaceToNbspFx('€ 1,00')];
yield [[], ['type' => 'atk4_money'], 12_345_678.3, $fixSpaceToNbspFx('€ 12 345 678.30')];
yield [[], ['type' => 'atk4_money'], -12_345_678.3, $fixSpaceToNbspFx('€ -12 345 678.30')];
yield [['decimalSeparator' => ','], ['type' => 'atk4_money'], 12_345_678.3, $fixSpaceToNbspFx('€ 12 345 678,30')];
yield [['thousandsSeparator' => ''], ['type' => 'atk4_money'], 12_345_678.3, $fixSpaceToNbspFx('€ 12345678.30')];
yield [['thousandsSeparator' => ','], ['type' => 'atk4_money'], 12_345_678.3, $fixSpaceToNbspFx('€ 12,345,678.30')];
Expand Down

0 comments on commit b9eb989

Please sign in to comment.