Skip to content

$page->preload() adds zero decimals to integers stored in FieldtypeDecimal #2080

Open
@tuomassalo

Description

@tuomassalo

Short description of the issue

When a Decimal field is preloaded, a stored integer value is returned with trailing .00. Without preloading, the value does not have .00.

Expected behavior

Preloading should not affect the result, only performance.

Actual behavior

$page->preload() causes the field value to show with trailing .00. With non-integer values, preloading does not affect the output.

Steps to reproduce the issue

See script below. Output:

Without preload: "42"
With preload: "42.00"

Setup/Environment

  • ProcessWire version: latest dev
  • (Optional) PHP version: 8.4
  • Database version: Mysql 8.0.39

The script:

<?php

$processwirePath = '/var/www/html/';
include($processwirePath . 'index.php');
header('Content-Type: text/plain');

// Remove field
$field = $fields->get('d');
if ($field) $fields->delete($field);

$template = $templates->get('name=home');

$dField = $fields->makeItem();
$dField->name = 'd';
$dField->type = 'Decimal';
$dField->save();
$template->fields->add($dField);
$template->save();

$p1 = $wire->pages->get(1);
$p1->d = 42;
$p1->save();

$wire->pages->uncacheAll();
$p1 = $wire->pages->get(1);

echo "Without preload: " . json_encode($p1->d) . "\n";


$wire->pages->uncacheAll();
$p1 = $wire->pages->get(1);
$p1->preload(['d']);

echo "With preload: " . json_encode($p1->d) . "\n";

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