This code:
if (dt.Subtract(prevDt).TotalMinutes == 15)
(“dt” and “prevDt” are DateTime vars that contain values such as “7/20/2012 7:30:00 AM” and “7/20/2012 7:45:00 AM”)
…causes ReSharper to warn me with:
“Comparison of floating point numbers with equality operator. Possible loss of precision while rounding values.”
Is this a valid warning, and if so, how would I appease it? I wish ReSharper were a little more like Eclipse, which offers to fix things it complains about.
At any rate, the code seems to work fine, although I’d rather not have it stink up the joint if this is a code smell.
If you are sure that your timestamps are exactly on 15 minute boundaries and not a few milliseconds off, then your code will work fine. Values that can be represented exactly as an
intcan also be represented exactly as a double.If you want to try to rewrite your code to avoid the warning, you might want to try this: