Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[PHP] Why is this incorrect?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Tue Oct 13, 2009 6:36 am    Post subject: [PHP] Why is this incorrect? Reply with quote

Code:
<?php
$eq = 23/3-round((23/3)-0.5,0);
$ans = 2/3;
if($eq==$ans) echo 'It is correct.';
?>


Both answers need to be 0.66666666667, but PHP says it's not. When I echo $eq and $ans they say the exact same.

Why is this incorrect?
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Oct 13, 2009 9:46 am    Post subject: Reply with quote

Imma reply here just in case someone else searches for this:
PHP manual wrote:
So never trust floating number results to the last digit, and never compare floating point numbers for equality.
Back to top
View user's profile Send private message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Tue Oct 13, 2009 10:25 am    Post subject: Reply with quote

Handled in IRC, can be closed
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites