php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11435 Floats are not handled correctly by printf?
Submitted: 2001-06-12 09:23 UTC Modified: 2001-06-12 13:23 UTC
From: tem at iocus dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0 Latest CVS (2001-06-12) OS: Linux (Mandrake & Redhat)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tem at iocus dot com
New email:
PHP Version: OS:

 

 [2001-06-12 09:23 UTC] tem at iocus dot com
<?php
$test="2.03";
$amount=($test*100);
echo $amount . "\n";
printf("%06d\n",$amount);
$amount=(2.03*100);
printf("%06d\n",$amount);
?>


Produces the following output:

203
000202
000202

My math is a little fuzzy but I think 2.03 * 100 = 203. This
used to work in php 3.x but seems to be broken since the 4.x
beta.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-12 13:23 UTC] sniper@php.net
The famous rounding issue.
By using 'f' (float) would give you correct result.
Not a bug.

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 16:01:30 2024 UTC