Bug #69039 [Com]: (int)

From: Date: Thu, 12 Feb 2015 11:41:14 +0000
Subject: Bug #69039 [Com]: (int)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190624@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69039&edit=1

 ID:                 69039
 Comment by:         nikic@php.net
 Reported by:        marc at webetsolutions dot com
 Summary:            (int)
 Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

(int) casts are truncating (which means "round down" in this case). Due to limited
floating point precision 264.40 * 100 is in reality something like 26439.999999999, which is then
rounded down to 26439. You may try setting the "precision" ini setting to a higher value
in order to see this.


Previous Comments:
------------------------------------------------------------------------
[2015-02-12 11:39:24] nikic@php.net

Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.



------------------------------------------------------------------------
[2015-02-12 09:26:36] marc at webetsolutions dot com

Description:
------------
Just a litle question

if i calculate 

echo 264.40 * 100;
The result is : 26440

if i calculate 
echo (int)(264.40 * 100);
The result is 26439

The problem seem to be for 255 to 327

Why ?



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



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


Thread (3 messages)

« previous php.bugs (#190624) next »