PB170
Well-known member
Just a simple C (Think C) question here. Can anyone explain why these two methods give different results? I have a decent understanding of how floating point numbers work in binary (5.67999…) and the problem with rounding during assignments, but I'm surprised that these two methods give different results. Could this be a Think C specific thing, or does it apply to C in general? (When I tried it with some online C compilers, both methods produce 568). Anyone who can enlighten me?
float float1 = 5.68;
float float2;
int integer;
Method 1:
integer = float1*100;
integer: 567
Method 2:
float2 = float1*100;
integer = float2;
integer: 568
float float1 = 5.68;
float float2;
int integer;
Method 1:
integer = float1*100;
integer: 567
Method 2:
float2 = float1*100;
integer = float2;
integer: 568
Last edited by a moderator: