php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29185 Error in output from sprintf()
Submitted: 2004-07-15 15:11 UTC Modified: 2004-07-19 22:45 UTC
From: hkh at netnords dot dk Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.7 OS: debian 3.0 - Apache 1.3.26
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hkh at netnords dot dk
New email:
PHP Version: OS:

 

 [2004-07-15 15:11 UTC] hkh at netnords dot dk
Description:
------------
I don't get the expected result from sprintf(), when input are less than [-]1.

Tried the same code on a php 5.0.0b3 (windows), where I got the expected result.

Maybe its related/oposite to bug #28633


Reproduce code:
---------------
$fmt = "%08.2f";
printf("[".$fmt."]<br />",   -10);
printf("[".$fmt."]<br />",    -1);
printf("[".$fmt."]<br />",    -0.995);
printf("[".$fmt."]<br />",    -0.99);
printf("[".$fmt."]<br />",    -0.5);
printf("[".$fmt."]<br />",     0);
printf("[".$fmt."]<br />",     0.5);
printf("[".$fmt."]<br />",     0.99);
printf("[".$fmt."]<br />",     0.995);
printf("[".$fmt."]<br />",     1);
printf("[".$fmt."]<br />",    10);


Expected result:
----------------
[-0010.00]
[-0001.00]
[-0001.00] // Not [-0000.99], should't it round down ?
[-0000.99]
[-0000.50]
[00000.00]
[00000.50]
[00000.99]
[00001.00] // Not [00000.99] , should't it round up ?
[00001.00]
[00010.00]

Actual result:
--------------
[-0010.00]
[-0001.00]
[-0000000.99]
[-0000000.99]
[-0000000.50]
[00000000.00]
[00000000.50]
[00000000.99]
[00000000.99]
[00001.00]
[00010.00]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-16 01:31 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Both PHP 4 and 5 return the same expected output. 
[-0010.00] 
[-0001.00] 
[-0000000.99] 
[-0000000.99] 
[-0000000.50] 
[00000000.00] 
[00000000.50] 
[00000000.99] 
[00000000.99] 
[00001.00] 
[00010.00] 
 [2004-07-19 22:33 UTC] derick@php.net
heh, how is this NOT a bug?
 [2004-07-19 22:45 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC