Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tuomassalo opened this issue May 29, 2025 · 0 comments

Comments

@tuomassalo
Copy link

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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants