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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 - 1 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC