|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-08 01:17 UTC] jose dot nobile at latinoaustralia dot com
Description: ------------ I have a strings with float numbers, in format integer.decimal (eg 916.32), and using operators (<,>,==,===) don't working as expecting. Additional info: System Windows NT WEBMASTER 5.1 build 2600 (Windows XP Professional Service Pack 3) i586 Build Date Jan 5 2011 20:26:24 Compiler MSVC9 (Visual C++ 2008) Architecture x86 Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--disable- isapi"http://bugs.php.net/bugs-generating-backtrace.php "--without-mssql" "-- without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=D:\php- sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php- sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=D:\php- sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "-- enable-com-dotnet" "--with-mcrypt=static" precision 14 14 serialize_precision 100 100 PROCESSOR_ARCHITECTURE x86 PROCESSOR_IDENTIFIER x86 Family 6 Model 15 Stepping 13, GenuineIntel PROCESSOR_LEVEL 6 PROCESSOR_REVISION 0f0d Intel Core 2 Duo CPU E4500 @ 2.2Ghz Download from: http://windows.php.net/download/ Test script: --------------- echo "<pre>"; $string1 = "932.16"; $substring1 = "3.16"; $substring2 = "454"; $substring3 = "475"; $number2 = floatval(floatval($substring1) + floatval($substring2) + floatval($substring3)); $number1 = floatval($string1); var_dump($number1);//expected: float(932.16), current: float(932.16), OK var_dump($number2);//expected: float(932.16), current: float(932.16), OK var_dump($number1 < $number2);//expected: bool(false), current: bool(true), FAIL var_dump($number1 > $number2);//expected: bool(false), current: bool(false), OK var_dump($number1 == $number2);//expected: bool(true), current: bool(false), FAIL var_dump($number1 === $number2);//expected: bool(true), current: bool(false), FAIL var_dump(bccomp($number1,$number2));//expected: int(0), current: int(0), OK echo "</pre>"; Expected result: ---------------- float(932.16) float(932.16) bool(false) bool(false) bool(true) bool(true) int(0) Actual result: -------------- float(932.16) float(932.16) bool(true) bool(false) bool(false) bool(false) int(0) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 11:00:01 2025 UTC |
I understand about IEEE 754 standard, Two's complement, Booth's Algorithm, and more. I found a workaround, $string = "1.123";//string $number = 1.123;//float $string2number = floatval($string); var_dump($number < $string2number);//Fail, <, >, ==, === all fail but .... $string = "1.123";//string $number = 1.123;//float $string2number = floatval($string); $float2float = floatval("$number");//float to string, string to float var_dump($string2number < $float2float);//OK, <, >, ==, === all OK This is a small fix, but complex to implement in all code. Other solutions: BCMath Arbitrary Precision Mathematics But, I question, is possible overwrite all Mathematics Operators with by example BCMath? some is possible overwrite string with Multi-Byte string functions? How is the correct to operate with floats? (in invoicing applications is critical point) Thanks.