|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78265 printf does not properly format decimals when using '%.8F'
Submitted: 2019-07-09 06:43 UTC Modified: 2019-07-09 07:50 UTC
From: mmucklo at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: I18N and L10N related
PHP Version: 7.3.7 OS: Linux / any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mmucklo at gmail dot com
New email:
PHP Version: OS:


 [2019-07-09 06:43 UTC] mmucklo at gmail dot com
printf does not properly format uppercase floats.

This is in the master branch and goes as far back as 5.6.40, but I didn't trace back any further.

The problem code is here:

It only pays attention to a lower case 'f'

WARNING - FIXING this could cause unsuspected results as this bug has been present as far back as 5.6.40 at least (the furthest back I looked).

Specifically the code in microtime calls into the printf function (eventually), and this will change the output of microtime() to be locale-specific.

This is not necessarily a bad thing, but there are perhaps libraries that expect the buggy behavior at this point (e.g. one that I presently maintain:

I'm not suggesting that it should not get fixed, but just to be cautious maybe where in the release cycle such a patch should go.

As a reference (couldn't instantly find a C version, but this CPP version seems accurate):

Also this Stackoverflow seems to clarify things. Pay particular attention to the second answer (about nan and inf capitalization), as I think PHP may do that wrong as well, although I didn't test it, but just looking at the code in spprintf.c, I don't see any specific logic to handle that case.

Test script:
// NOTE your system needs to have this locale loaded first
//  On ubuntu 19 which I'm using (via docker) do the following
//  from the shell prompt (if you are not root, become root, or prefix with sudo):
//  locale-gen de_DE
//  locale-gen de_DE.UTF-8
//  dpkg-reconfigure locales
//  # you may also need the locales package installed (apt install locales).

$loc_de = setlocale(LC_ALL, 'de_DE.UTF-8', 'de_DE', 'de', 'ge');

printf("%0.8f\n", 0.12345);
printf("%0.8F\n", 0.12335);

// One should show the comma, the other won't


Here is some C code to reproduce the expected result

#include <stdio.h>
#include <locale.h>

int main(int argc, char**argv) {
	setlocale(LC_ALL, "de_DE.UTF-8");
	printf("%.8f\n", 0.12345);
	printf("%.8F\n", 0.12335);
	return 0;


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-09 07:28 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2019-07-09 07:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

See <>.
 [2019-07-09 07:50 UTC] mmucklo at gmail dot com
Sigh - RTM and you’re absolutely correct, expected behavior.

Back to figuring out the locale related issue the user was having which is clearly due to some other reason.

Thanks for your time and sorry for not catching that beforehand.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 12 12:01:24 2021 UTC