Skip to content

Commit

Permalink
store only selected num of decimals & ensure the same behaviour as in v4
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Nov 22, 2024
1 parent 2ecb86c commit 5430424
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fields/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ private function _normalizeNumber(mixed $value): float|int|string|null
return null;
}

// ensure we only store the selected number of decimals and that the result is the same as in v4
// https://github.com/craftcms/cms/issues/16181
if (isset($this->decimals)) {
if ($this->decimals === 0) {
$value = (int)$value;
} else {
$value = number_format($value, $this->decimals, '.');
}
}

if (is_string($value) && is_numeric($value)) {
if ((int)$value == $value) {
return (int)$value;
Expand Down

0 comments on commit 5430424

Please sign in to comment.