
May 8th, 2008, 12:39 PM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 1
Time spent in forums: 27 m 17 sec
Reputation Power: 0
|
|
Float value types - huh?
I'm a noob, so please don't laugh. I'm trying to write a program, found this problem, extrapolated the most basic code i could, and the same problem occures:
float f1 = 6.21f;
float f2 = 6.18f;
float f3 = f2 - f1;
Console.WriteLine(string.Format("{0} - {1} = {2}", f2, f1, f3));
output: 6.18 - 6.21 = -0.03000021
Where is this extra data comming from? I need this to be more accurate, the answer should be exactly -0.03. Can anyone explain this to me? Or suggest an alternative? I also tried using doubles, but the output was just as strange...
|