c# - Decimal.ToUInt64 "Value was either too large or too small for a UInt64 -
i doing: -
decimal production = 0; decimal expense = 5000; decimal.touint64(production - expense);
but throws exception following error message.
"value either large or small uint64"
can give me workaround this.
thanks!
edit
in case, want result positive number.
problem: -5000m negative number, outside range of uint64
(an unsigned type).
solution: use int64
instead of uint64
if want cope negative numbers.
note can cast instead of calling decimal.to...
:
long x = (long) (production - expense);
alternative: validate number non-negative before trying convert it, , deal deem appropriate.
very dodgy alternative: if really want absolute value (which seems unlikely) use math.abs
:
uint64 alwaysnonnegative = decimal.touint64(math.abs(production - expense));
Comments
Post a Comment