php / php/php-src

printf negative zero inconsistency

Open
#12,237 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The following code:

<?php

var_dump(sprintf('%.2f%%', -0.0));

var_dump(sprintf('%.2f%%', -0.001));

https://3v4l.org/MbC3V

Resulted in this output:

string(5) "0.00%"
string(6) "-0.00%"

But I expected this output instead:

string(5) "0.00%"
string(5) "0.00%"
PHP Version

any

Operating System

any

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

Reproduce the discrepancy from the issue's sprintf example and compare the handling of -0.0 and -0.001 in the PHP interpreter's formatting path. Trace the sprintf implementation to identify where the sign is retained, then add regression coverage showing the expected output for both values.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.