Since 0.4
cannot be exactly represented in the Double
floating-point format, you get its nearest representation, which in the case of (23.4-23)*100
is probably something like 39.999999999999858
. When you use (int)
, you truncate the fraction, leaving you with 39.
You need to round instead of truncate, so use (int)Math.Round(minute)
.
Alternatively, you can use the Decimal
type, which can exactly represent decimal numbers like 23.40
.