Skip to content

FieldtypeDecimal: "Warning: 1265 Data truncated for column 'data' at row 1" #2055

Open
@hgassen

Description

@hgassen

Setup:

  • ProcessWire latest
  • PHP 7.4 (!)
  • Using locale where decimal separator is a comma (not a dot), e.g. de_DE.utf8
  • Field with FieldtypeDecimal (core), configured with 2 decimals

When trying to save a page with the (changed) decimal field in admin, I get the error

Warning: 1265 Data truncated for column 'data' at row 1

The new value is not saved. The error does not occur on PHP >= 8.0

The problem seems to be here:

https://github.com/processwire/processwire/blob/6783c4824b8a3b0afec18e2922c6bd8eec23aa94/wire/core/Sanitizer.php#L4545

After this line, the string $value has a decimal comma (instead of a dot).

For my use case, I could fix it by replacing this line with

$value = stripos("$value", 'E') ? rtrim(sprintf("%.15$f", (float) $value), '0') : number_format($value, 2, '.', '');

But there might be <> 2 decimals...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions