ID:               43053
 Comment by:       admin at vr-realty dot com
 Reported By:      owner at dragon-hearts dot net
 Status:           Verified
 Bug Type:         Scripting Engine problem
 Operating System: Centos4
 PHP Version:      5CVS-2007-10-25
 New Comment:

I had a working database for my office Stock Trading Pool when
AAAHHHHkkk 1.23E+007. The non programmers there were all freaked the
hell out. They thought E meant Error and that we had lost all of our
money. trying to tell 70+ people, that haven't seen Scientific notation
since they were in 9th grade, that it's not a problem and we will fix it
was no easy task. By the time it was brought to my attention people had
already started trying to figure out how to sue me for losing their
money, yeah it was a mess. And they didn't know that what they see is
just a thing for them to see and reference and really could be forgotten
and not updated for days. 

anyways 

I wen through and changed the MySql DB from floats to VarChars. and
type casted the $vars I pulled from the DB to float using

$curprice = (float)$price;
 and the ones that could be int like the number of shares
$curshares = (int)$shares;
 then I did the math
$total = (float)($price*$shares);

now the General population is feeling at ease and the death threats
have subsided. I'm still trying to understand why Scientific notation
would come into play.

maybe it sould be an obscure function like INT_TO_SCI($var) or
num_to_sci($var) ..

like the automatic and natural way to have the numbers over millions
sould be preserved as a whole long string no matter what the length with
the option to convert it to scientific notation if that suits your
needs.

my 2cents


Previous Comments:
------------------------------------------------------------------------

[2008-03-06 15:56:45] rbro at hotmail dot com

I agree - to me, this is a BC break that wasn't listed on any changelog
or announcement.  I have been holding off on upgrading my PHP version to
anything later than 5.2.1 because of this issue.

------------------------------------------------------------------------

[2008-03-04 23:07:43] tech at dragonara dot net

We have the same bug, and really - cPanel does not support 5.1 anymore,
so we are really in stupid situation.

------------------------------------------------------------------------

[2008-02-09 13:20:23] lhfagundes at gmail dot com

This gets bad if the float is casted to string (which happens if it
goes through requests):

$x = 1200000000.00;
echo $x . "\n";
echo (int)$x . "\n";
$x = "$x";
echo (int) $x . "\n";

In PHP 4.4.2 (I guess in earlier php5 too)

1200000000
1200000000
1200000000

now:

1.2E+9
1200000000
1

------------------------------------------------------------------------

[2008-01-28 13:39:47] gcleaves at yahoo dot com dot au

Same problem:

PHP Version 5.2.4
Windows NT HGCT-SQL 5.2 build 3790
Apache 2.0 Handler

------------------------------------------------------------------------

[2008-01-26 02:18:38] [EMAIL PROTECTED]

This issue is still present in PHP 5.2.5 (FreeBSD). It only happens on
some floats. 

If there is a reason for using E-notation in this case - which could be
argued, although I feel changing past behavior is not necessary,
especially as MySQL has trouble handling these values in common
scenarios - it should be made consistent so people can depend on it and
prevent problems by testing.

<?php

echo phpversion() . "\n";
echo 2700000.0;
echo "\n";
echo 2800000.0;
echo "\n";
echo 2900000.0;
echo "\n";

?>

devwh:~> php floats.php
5.2.1
2700000
2800000
2900000

test:~> php floats.php
5.2.4
2700000
2.8E+6
2900000

toms1:~> php floats.php
5.2.5
2700000
2.8E+6
2900000

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/43053

-- 
Edit this bug report at http://bugs.php.net/?id=43053&edit=1

Reply via email to