#36008 [Opn]: incorrect round() & number_format() result

2006-10-30 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
 Status:   Open
 Bug Type: Math related
 Operating System: win32 only
 PHP Version:  5CVS-2006-06-14
 New Comment:

Aww well it's too late for me to bug it for Windows Vista as we've
entered Release Candidate 2 :(  I'll test this again on IIS7 with the
final version of Vista...


Previous Comments:


[2006-10-30 13:30:58] dave at koales dot co dot uk

I think this is a Windows vs others thing.  I have the same rounding
error using PHP 5.0.5 on Windows XP SP2.

The same problem does not exist on my webhost, who use PHP 4.3.9 and
Redhat Linux (need any more detail).

The code I used was:

echo "Correct VAT = " . round( 0.525, 2 ) . "\r\n";
echo "Wrong VAT = " .  round( 3 * ( 17.5 / 100.0 ), 2 ) . "\r\n";

Outputs 0.53 for each on webhost (under Linux) and 0.52 for the second
test under Windows (0.53 for the first test).

I've also had very bizarre rounding errors with MySQL.  The rounding
error came and went depending on how the calculation was constructed!

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

[2006-10-10 21:44:21] adi at rogers dot com

Amen to that ;)



[2006-10-10 07:45:36] troy20 at mail dot ru

Code:
for ($i = 1.075;$i <= 1.975;$i=$i+0.1)
{echo round($i,2);}
Result:
1.08, 1.18, 1.28, 1.38
But if
echo round(1.275,2);
echo round(1.275*100);
we have 1.27 and 127. 

Another "same" example:
for ($i = 1.075;$i <= 20.975;$i=$i+0.1)
{echo round($i,2);}

Win2003 + Apache 2.0.59 + php 5.1.6

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

[2006-06-14 22:11:53] adi at rogers dot com

Regretfully, the same output:

5.2.0-dev

Wrong: 14.37
Wrong: 14.37
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38


The 32 precision results are also the same [as the ones on January 15].



[2006-06-14 15:50:08] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip





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/36008

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


#36008 [Opn]: incorrect round() & number_format() result

2006-10-10 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
 Status:   Open
 Bug Type: Math related
 Operating System: win32 only
 PHP Version:  5CVS-2006-06-14
 New Comment:

Amen to that ;)


Previous Comments:


[2006-10-10 07:45:36] troy20 at mail dot ru

Code:
for ($i = 1.075;$i <= 1.975;$i=$i+0.1)
{echo round($i,2);}
Result:
1.08, 1.18, 1.28, 1.38
But if
echo round(1.275,2);
echo round(1.275*100);
we have 1.27 and 127. 

Another "same" example:
for ($i = 1.075;$i <= 20.975;$i=$i+0.1)
{echo round($i,2);}

Win2003 + Apache 2.0.59 + php 5.1.6



[2006-06-14 22:11:53] adi at rogers dot com

Regretfully, the same output:

5.2.0-dev

Wrong: 14.37
Wrong: 14.37
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38


The 32 precision results are also the same [as the ones on January 15].



[2006-06-14 15:50:08] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip



--------

[2006-01-15 06:40:25] adi at rogers dot com

Oh, and as I had suspected, here is the value of $num with 32
precision: 14.3749998
With 12 as the precision, it is: 14.375

--------

[2006-01-15 06:34:25] adi at rogers dot com

As requested, the exact output with 32 as the precision:

Wrong: 14.369
Wrong: 14.37
'Magically' correct: 14.381
'Magically' correct: 14.38
Converted to string and is now correct: 14.369
Converted to string and is now correct: 14.37



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/36008

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


#36008 [Fbk->Opn]: incorrect round() & number_format() result

2006-06-14 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Math related
 Operating System: win32 only
 PHP Version:  5.1.2
 New Comment:

Regretfully, the same output:

5.2.0-dev

Wrong: 14.37
Wrong: 14.37
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38


The 32 precision results are also the same [as the ones on January 15].


Previous Comments:


[2006-06-14 15:50:08] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip





[2006-01-15 06:40:25] adi at rogers dot com

Oh, and as I had suspected, here is the value of $num with 32
precision: 14.3749998
With 12 as the precision, it is: 14.375



[2006-01-15 06:34:25] adi at rogers dot com

As requested, the exact output with 32 as the precision:

Wrong: 14.369
Wrong: 14.37
'Magically' correct: 14.381
'Magically' correct: 14.38
Converted to string and is now correct: 14.369
Converted to string and is now correct: 14.37



[2006-01-14 16:06:25] [EMAIL PROTECTED]

What EXACTLY is the output when you set precision to 32?


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

[2006-01-14 15:55:07] adi at rogers dot com

I just confirmed this issue to still exist on the following systems:

Windows XP Pro SP2 [IIS 5.1 ISAPI] (PHP 5.1.2 / php.ini precision: 12)
Windows XP Pro SP2 [IIS 5.1 CGI] (PHP 5.1.0RC1 / php.ini precision:
12)
Windows Server 2003 Enterprise x64 Edition SP1 [IIS 6.0 CGI] (PHP 5.1.2
/ php.ini precision: 12)

PHP was installed on all three systems manually (not using the
installer).

Hope that helps in isolating this issue.



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/36008

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


#36008 [Opn]: Mishandled type 'double' causes incorrect round() & number_format() output

2006-01-14 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
 Status:   Open
 Bug Type: Math related
 Operating System: win32 only
 PHP Version:  5.1.2
 New Comment:

Oh, and as I had suspected, here is the value of $num with 32
precision: 14.3749998
With 12 as the precision, it is: 14.375


Previous Comments:


[2006-01-15 06:34:25] adi at rogers dot com

As requested, the exact output with 32 as the precision:

Wrong: 14.369
Wrong: 14.37
'Magically' correct: 14.381
'Magically' correct: 14.38
Converted to string and is now correct: 14.369
Converted to string and is now correct: 14.37



[2006-01-14 16:06:25] [EMAIL PROTECTED]

What EXACTLY is the output when you set precision to 32?




[2006-01-14 15:55:07] adi at rogers dot com

I just confirmed this issue to still exist on the following systems:

Windows XP Pro SP2 [IIS 5.1 ISAPI] (PHP 5.1.2 / php.ini precision: 12)
Windows XP Pro SP2 [IIS 5.1 CGI] (PHP 5.1.0RC1 / php.ini precision:
12)
Windows Server 2003 Enterprise x64 Edition SP1 [IIS 6.0 CGI] (PHP 5.1.2
/ php.ini precision: 12)

PHP was installed on all three systems manually (not using the
installer).

Hope that helps in isolating this issue.



[2006-01-14 11:16:57] [EMAIL PROTECTED]

Output on my machine using default precision 12:
Wrong: 14.38
Wrong: 14.38
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38

And it works exactly like it's supposed to.
round() rounds up to 2 decimals. Same goes for number_format(). 

14.375 == 14.38 but 14.374 == 14.37

There is no bug here, and please, don't bother reopening this yet
again.

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

[2006-01-14 05:15:52] adi at rogers dot com

Description:

Very lame/unreliable ;)
Both round() and number_format() succumb to this problem.
They cannot handle float or double variables properly even though those
variable types are "flawed / limited" as apparently described numerous
times on here by PHP personnel. Well my code below appears to showcase
the bug which will hopefully not be shot off as "bogus" like many times
before as reported in the past by various people.

I found a work-around which I will now be using. Convert your value to
a string variable before passing it to the round() or number_format()
function.

Reproduce code:
---
$num=12.5*1.15;// Produces 14.375 as type: double.
$num_same_thing=14.375; // Produces 14.375 as type: double.
echo "Wrong: ".round($num, 2)."\r\n";
echo "Wrong: ".number_format($num, 2)."\r\n";
echo "'Magically' correct: ".round($num_same_thing, 2)."\r\n";
echo "'Magically' correct: ".number_format($num_same_thing, 2)."\r\n";
// The above two variables are the same value and same type, yet are
rounded differently.
settype($num, "string");
// Now that $num is a string, we get the right result.
echo "Converted to string and is now correct: ".round($num, 2)."\r\n";
echo "Converted to string and is now correct: ".number_format($num,
2)."\r\n";

Expected result:

The functions should have outputted 14.38 no matter how the variables
of type 'double' were assigned the value 14.375.






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


#36008 [Fbk->Opn]: Mishandled type 'double' causes incorrect round() & number_format() output

2006-01-14 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Math related
 Operating System: win32 only
 PHP Version:  5.1.2
 New Comment:

As requested, the exact output with 32 as the precision:

Wrong: 14.369
Wrong: 14.37
'Magically' correct: 14.381
'Magically' correct: 14.38
Converted to string and is now correct: 14.369
Converted to string and is now correct: 14.37


Previous Comments:


[2006-01-14 16:06:25] [EMAIL PROTECTED]

What EXACTLY is the output when you set precision to 32?




[2006-01-14 15:55:07] adi at rogers dot com

I just confirmed this issue to still exist on the following systems:

Windows XP Pro SP2 [IIS 5.1 ISAPI] (PHP 5.1.2 / php.ini precision: 12)
Windows XP Pro SP2 [IIS 5.1 CGI] (PHP 5.1.0RC1 / php.ini precision:
12)
Windows Server 2003 Enterprise x64 Edition SP1 [IIS 6.0 CGI] (PHP 5.1.2
/ php.ini precision: 12)

PHP was installed on all three systems manually (not using the
installer).

Hope that helps in isolating this issue.



[2006-01-14 11:16:57] [EMAIL PROTECTED]

Output on my machine using default precision 12:
Wrong: 14.38
Wrong: 14.38
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38

And it works exactly like it's supposed to.
round() rounds up to 2 decimals. Same goes for number_format(). 

14.375 == 14.38 but 14.374 == 14.37

There is no bug here, and please, don't bother reopening this yet
again.

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

[2006-01-14 05:15:52] adi at rogers dot com

Description:

Very lame/unreliable ;)
Both round() and number_format() succumb to this problem.
They cannot handle float or double variables properly even though those
variable types are "flawed / limited" as apparently described numerous
times on here by PHP personnel. Well my code below appears to showcase
the bug which will hopefully not be shot off as "bogus" like many times
before as reported in the past by various people.

I found a work-around which I will now be using. Convert your value to
a string variable before passing it to the round() or number_format()
function.

Reproduce code:
---
$num=12.5*1.15;// Produces 14.375 as type: double.
$num_same_thing=14.375; // Produces 14.375 as type: double.
echo "Wrong: ".round($num, 2)."\r\n";
echo "Wrong: ".number_format($num, 2)."\r\n";
echo "'Magically' correct: ".round($num_same_thing, 2)."\r\n";
echo "'Magically' correct: ".number_format($num_same_thing, 2)."\r\n";
// The above two variables are the same value and same type, yet are
rounded differently.
settype($num, "string");
// Now that $num is a string, we get the right result.
echo "Converted to string and is now correct: ".round($num, 2)."\r\n";
echo "Converted to string and is now correct: ".number_format($num,
2)."\r\n";

Expected result:

The functions should have outputted 14.38 no matter how the variables
of type 'double' were assigned the value 14.375.






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


#36008 [Bgs->Opn]: Mishandled type 'double' causes incorrect round() & number_format() output

2006-01-14 Thread adi at rogers dot com
 ID:   36008
 User updated by:  adi at rogers dot com
 Reported By:  adi at rogers dot com
-Status:   Bogus
+Status:   Open
 Bug Type: Math related
 Operating System: Windows XP or Server 2003
 PHP Version:  5.1.2
 New Comment:

I just confirmed this issue to still exist on the following systems:

Windows XP Pro SP2 [IIS 5.1 ISAPI] (PHP 5.1.2 / php.ini precision: 12)
Windows XP Pro SP2 [IIS 5.1 CGI] (PHP 5.1.0RC1 / php.ini precision:
12)
Windows Server 2003 Enterprise x64 Edition SP1 [IIS 6.0 CGI] (PHP 5.1.2
/ php.ini precision: 12)

PHP was installed on all three systems manually (not using the
installer).

Hope that helps in isolating this issue.


Previous Comments:


[2006-01-14 11:16:57] [EMAIL PROTECTED]

Output on my machine using default precision 12:
Wrong: 14.38
Wrong: 14.38
'Magically' correct: 14.38
'Magically' correct: 14.38
Converted to string and is now correct: 14.38
Converted to string and is now correct: 14.38

And it works exactly like it's supposed to.
round() rounds up to 2 decimals. Same goes for number_format(). 

14.375 == 14.38 but 14.374 == 14.37

There is no bug here, and please, don't bother reopening this yet
again.

--------

[2006-01-14 05:15:52] adi at rogers dot com

Description:

Very lame/unreliable ;)
Both round() and number_format() succumb to this problem.
They cannot handle float or double variables properly even though those
variable types are "flawed / limited" as apparently described numerous
times on here by PHP personnel. Well my code below appears to showcase
the bug which will hopefully not be shot off as "bogus" like many times
before as reported in the past by various people.

I found a work-around which I will now be using. Convert your value to
a string variable before passing it to the round() or number_format()
function.

Reproduce code:
---
$num=12.5*1.15;// Produces 14.375 as type: double.
$num_same_thing=14.375; // Produces 14.375 as type: double.
echo "Wrong: ".round($num, 2)."\r\n";
echo "Wrong: ".number_format($num, 2)."\r\n";
echo "'Magically' correct: ".round($num_same_thing, 2)."\r\n";
echo "'Magically' correct: ".number_format($num_same_thing, 2)."\r\n";
// The above two variables are the same value and same type, yet are
rounded differently.
settype($num, "string");
// Now that $num is a string, we get the right result.
echo "Converted to string and is now correct: ".round($num, 2)."\r\n";
echo "Converted to string and is now correct: ".number_format($num,
2)."\r\n";

Expected result:

The functions should have outputted 14.38 no matter how the variables
of type 'double' were assigned the value 14.375.






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


#36008 [NEW]: Mishandled type 'double' causes incorrect round() & number_format() output

2006-01-13 Thread adi at rogers dot com
From: adi at rogers dot com
Operating system: Windows XP or Server 2003
PHP version:  5.1.2
PHP Bug Type: Math related
Bug description:  Mishandled type 'double' causes incorrect round() & 
number_format() output

Description:

Very lame/unreliable ;)
Both round() and number_format() succumb to this problem.
They cannot handle float or double variables properly even though those
variable types are "flawed / limited" as apparently described numerous
times on here by PHP personnel. Well my code below appears to showcase the
bug which will hopefully not be shot off as "bogus" like many times before
as reported in the past by various people.

I found a work-around which I will now be using. Convert your value to a
string variable before passing it to the round() or number_format()
function.

Reproduce code:
---
$num=12.5*1.15;// Produces 14.375 as type: double.
$num_same_thing=14.375; // Produces 14.375 as type: double.
echo "Wrong: ".round($num, 2)."\r\n";
echo "Wrong: ".number_format($num, 2)."\r\n";
echo "'Magically' correct: ".round($num_same_thing, 2)."\r\n";
echo "'Magically' correct: ".number_format($num_same_thing, 2)."\r\n";
// The above two variables are the same value and same type, yet are
rounded differently.
settype($num, "string");
// Now that $num is a string, we get the right result.
echo "Converted to string and is now correct: ".round($num, 2)."\r\n";
echo "Converted to string and is now correct: ".number_format($num,
2)."\r\n";

Expected result:

The functions should have outputted 14.38 no matter how the variables of
type 'double' were assigned the value 14.375.


-- 
Edit bug report at http://bugs.php.net/?id=36008&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36008&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36008&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36008&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36008&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=36008&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=36008&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=36008&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=36008&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=36008&r=support
Expected behavior:http://bugs.php.net/fix.php?id=36008&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=36008&r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=36008&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36008&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36008&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36008&r=dst
IIS Stability:http://bugs.php.net/fix.php?id=36008&r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=36008&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36008&r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=36008&r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=36008&r=mysqlcfg