Ctype casting to Decimal returning negative value
-
27-10-2019 - |
Question
I am wondering if this is a bug. Can't understand why would CType work this way...!
Solution
This happens because enclosing a value in ()
means it is a negative number.
It is a standard financial notation for amounts that are deducted.
When a number is parsed, if NumberStyles.AllowParentheses
is set for NumberStyles
, then they will be interpreted as a negative value.
See Parsing numeric strings on MSDN:
NumberStyles.AllowParentheses
Parentheses can be used to indicate negative values.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow