[php-src] Issue #18897: printf: empty precision is interpreted as precision 6, not as precision 0
| From: | bhaible | Date: | Sun, 22 Jun 2025 00:46:50 +0000 |
| Subject: | [php-src] Issue #18897: printf: empty precision is interpreted as precision 6, not as precision 0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250294@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18897
Author: bhaible
### Description
The following code:
```php
<?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
```plain
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_