php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44051 Bug report for sprintf
Submitted: 2008-02-05 17:59 UTC Modified: 2008-02-05 20:16 UTC
From: andyhaslam at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.5 OS: WHM/Apache/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andyhaslam at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-02-05 17:59 UTC] andyhaslam at hotmail dot com
Description:
------------
An interesting bug, if you do the following:

$val = 2345.35;
$val = sprintf("%01.2f", $val);
echo $val;

Output is "2.00", instead of "2345.35". The solution is to use an intermediate variable:

$val = 2345.35;
$val2 = sprintf("%01.2f", $val);
$val = $val2;
echo $val;

Reproduce code:
---------------
$val = 2345.35;
$val = sprintf("%01.2f", $val);
echo $val;


Expected result:
----------------
2345.35

Actual result:
--------------
2.00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-05 20:16 UTC] msaraujo@php.net
Hello,

It works fine here (PHP 5.2.5, PHP 5.3-snap and PHP 6).


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 14:01:33 2025 UTC