Skip to content

[5.x]: Number field without decimals returned with decimal points from advanced queries #16369

@chrismlusk

Description

@chrismlusk

What happened?

Description

I have a Number field with Decimal Points set to 0. When executing an entry query with all(), one(), etc., the value is returned as an integer with no decimal points, as expected. But when using methods such as scalar(), pairs(), column(), the value is returned as a string with 16 decimal points.

// Given a field named `myNumberField` with a value of "99"...

// This returns 99 as an integer
Entry::find()
    ->id($entryId)
    ->one()
    ->myNumberField;

// But this returns "99.0000000000000000"
Entry::find()
    ->id($entryId)
    ->select('myNumberField')
    ->scalar();

This is for a project where I am upgrading from Craft v4. None of these queries have been modified, and they were previously returning the expected values.

Steps to reproduce

  1. Create a Number field and set Decimal Points to 0.
  2. Add field to an entry type and create an entry with an integer as the field value.
  3. Query for that entry, select the Number field, and execute the query using scalar().

Expected behavior

Value should be returned without decimal points.

Actual behavior

Value is returned with decimal points.

Craft CMS version

5.5.7

PHP version

8.3

Operating system and version

No response

Database type and version

MySQL 8.0.36

Image driver and version

No response

Installed plugins and versions

No response

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