Bug #75558 [Com]: Float to integer conversion

From: Date: Thu, 23 Nov 2017 10:59:28 +0000
Subject: Bug #75558 [Com]: Float to integer conversion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212687@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75558&edit=1

 ID:                 75558
 Comment by:         spam2 at rhsoft dot net
 Reported by:        cyrille dot php at giquello dot fr
 Summary:            Float to integer conversion
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   Ubuntu 16.04
 PHP Version:        7.1.11
 Block user comment: N
 Private report:     N

 New Comment:

that's indeed a joke

php > echo 103.24 * 6 * 10**2;
61944

php > echo round(( 103.24 * 6 * 10**2));
61944

php > echo (int)( 103.24 * 6 * 10**2);
61943


Previous Comments:
------------------------------------------------------------------------
[2017-11-23 10:59:00] cyrille dot php at giquello dot fr

Another test script:

Test script:
---------------

php -r '$a=( 103.24*6*10**2); echo
$a,"=",intval($a),"=",intval(61944.0),"\n";'

Expected result:
----------------

61944=61944=61944

Actual result:
--------------

61944=61943=61944

------------------------------------------------------------------------
[2017-11-23 10:50:23] cyrille dot php at giquello dot fr

Description:
------------
Hi,

I've read the warning about float on documentation  http://php.net/manual/fr/language.types.float.php
but for simple computing it should be nice if Php return value like other languages (Python &
Java).

The computing (int)( 103.24 * 6 * 10**2) should return 61944 nor 61943.

I've done the same with Java & Python (converting float result to integer) and get the
right result: 61944



Test script:
---------------
php -r 'echo (int)( 103.24 * 6 * 10**2),"\n";'


Expected result:
----------------
61944

Actual result:
--------------
61943


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



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


Thread (9 messages)

« previous php.bugs (#212687) next »