Skip to content

Wrong decimal number in atk4_money type typecast #2234

@mkrecek234

Description

@mkrecek234

Following the ATK4 Discord Help conversation, here is the summary:

  • Store a value, e.g., -172158.01 in an atk4_money field.
  • It is wrongly typecasted as € -172.158,01000000001

Reason is that

$valueDecimals = strlen(preg_replace('~^[^.]$|^.+\.|0+$~s', '', number_format($value, max(0, 11 - (int) log10($value)), '.', '')));
calculates the wrong number of decimals of any given number.

Here is an alternative calculation of $valueDecimals for that given line which is working:
$valueDecimals = ($decimalPos = strrchr((string) $value, '.')) ? strlen($decimalPos) -1 : 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions