I have the following code:
DateTime PunchIn = DateTime.Parse("12/10/2015 5:06:00 PM");
DateTime PunchOut = DateTime.Parse("12/10/2015 5:30:00 PM");
double WorkedTime;
WorkedTime = (PunchOut - PunchIn).TotalHours;
MessageBox.Show(WorkedTime.ToString());
The value of WorkedTime should be 0.4 (24/60).
But as you can see from the following screenshot, the calculated value is 0.39999999...
But to make it even more confusing, the MessageBox displays the calculated value as 0.4
Can anyone help explain this seemingly bizarre behavior?
EDIT: If this is a "floating point inaccuracy", what is the work around so I can get the answer of 0.4 in my code?