Skip to content

printf: empty precision is interpreted as precision 6, not as precision 0 #18897

Open
@bhaible

Description

@bhaible

Description

The following code:

<?php
  printf("%.f\n", 3.1415926535);
  printf("%.0f\n", 3.1415926535);
  printf("%.6f\n", 3.1415926535);
?>

Resulted in this output:

3.141593
3
3.141593

But I expected this output instead:

3
3
3.141593

because the documentation (https://www.php.net/manual/en/function.printf.php and https://www.php.net/manual/en/function.sprintf.php) says "Note: If the period is specified without an explicit value for precision, 0 is assumed."

PHP Version

PHP 8.3.6 (cli) (built: Mar 19 2025 10:08:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Operating System

No response

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