If this is not for printing, you should not care about the error. 337.36080000000004 is exactly the same as 337.3608, since you have only 5 significant digits in the coefficient and only 3 in the test input. (And I certainly hope the answer to your method gave 331, not 337)
However, this line, derived from another question , seems to do the trick too.
double toFeet = ((int)(meters*3.2808*10000))/10000.0;
The only problem is that overflow is much faster.
source
share