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
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: 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: Tue Dec 10 00:01:28 2024 UTC