I'm trying to convert from a price to the smallest currency unit. Eg. when receiving the value 9.45 it should produce the result 945. The conversion code should take a double and convert it to an int while maintaining a two decimal precision.
This C# console code gives me a strange rounding error.
double val = 9.45d;
var result = (int)(val * 100);
System.Console.WriteLine("Result is " + result); // 944
The result of the code snippet is 944 which baffles me. What's wrong?