Skip to content

European number format change amount on save when use dot as comma #1227

@sudwebdesign

Description

@sudwebdesign

Step to reproduce

1: Select european format (1.000.000,00) for numbers in setting page
2: Set amount with dot as comma (on the numeric keypad, the comma is a dot)
3: save the invoice

Screenshots

Actually

Image

Expected

Image

Note: All values are hand filled before, when darkens become == click on save and when lightens it's the saved values returned by server.

Possible solution

Change standardize_amount function in helpers/number_helper.php with that

function standardize_amount($amount)
{
    if ($amount && ! is_numeric($amount))
    {
        $CI = & get_instance();
        $thousands_separator = $CI->mdl_settings->setting('thousands_separator');
        $decimal_point = $CI->mdl_settings->setting('decimal_point');

        if ($thousands_separator == '.' && ! substr_count($amount, ',') && substr_count($amount, '.') > 1)
        {
            $amount[ strrpos($amount, '.') ] = ','; // Replace last position of dot to comma
        }

        $amount = strtr($amount, [$thousands_separator => '', $decimal_point => '.']);
    }
    return $amount;
}

Note

This fix improve the function

  • Applied only on not numeric
  • str_replace to strtr
  • Replace last position of dot to comma if don't have a comma
  • And work with all number format chosen by user

This not solve all problems of typos like 1.00.0 > 100,00 but just trust on human intellect after all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions