php / php/php-src

number_format rounding in 8.4 is different from older versions

Open
#18,266 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Invalid
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description
<?php

$a = [0.06,0.0025,0.0225,0.01];

$s = array_sum($a);
echo $s . "\n";

echo number_format($s, 2, '.', '');
Output for 8.4.1 - 8.4.5
    0.095
    0.09
Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.19
    0.095
    0.10

https://3v4l.org/WQVRub

PHP Version

8.4.5

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the number_format() entry point and the supplied reproducer, then compare its behavior across the listed PHP 8.2, 8.3, and 8.4 versions. Determine which rounding behavior is intended and verify that the final behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.