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

From: Date: Wed, 14 Jun 2006 15:50:08 +0000
Subject: #36008 [Opn->Fbk]: incorrect round() & number_format() result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-98349@lists.php.net to get a copy of this message
ID: 36008 Updated by: iliaa@php.net Reported By: adi at rogers dot com -Status: Open +Status: Feedback Bug Type: Math related Operating System: win32 only PHP Version: 5.1.2 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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.374999999999998 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.369999999999999 Wrong: 14.37 'Magically' correct: 14.380000000000001 'Magically' correct: 14.38 Converted to string and is now correct: 14.369999999999999 Converted to string and is now correct: 14.37 ------------------------------------------------------------------------ [2006-01-14 16:06:25] sniper@php.net 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] sniper@php.net 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. ------------------------------------------------------------------------ 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

« previous php.bugs (#98349) next »