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 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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 23 18:05:03 2020 UTC