Try (int)(amount*1000) . In Convert brackets ensure priority is respected, but cast (int) takes precedence over multiplication - so you have: ((int)amount)*1000 , which rounds (during translation) to 9.
In particular, see "7.2.1 Operator Priority and Associativity" in the MS specification, which defines the throw before multiplication:
- 7.5: Primary: xy f (x) a [x] x ++ x-- new default type checked unchecked delegate
- 7.6: Unary: + -! ~ ++ x --x (T) x
- 7.7: Multiplicative: * /%
- etc.
source share