简体   繁体   English

ulong 和 0 之间的 If 语句

[英]If statement between ulong and 0

Im trying to do this calculation but its trying to convert a ulong to an int to see if its less than 0. Ive tried getting rid of int and putting it before the 0 instead but its not working at all.我正在尝试进行此计算,但它试图将 ulong 转换为 int 以查看它是否小于 0。我尝试摆脱 int 并将其放在 0 之前,但它根本不起作用。

ulong a = -897324782938287523942985;
ulong b = 95;
if ((int)(a + (b * 10000)) < 0) 
{
 a += (b*10000)
} else {
 a += b;
}

which gives the error:这给出了错误:

Exception trown: 'System.OverflowException' in mscorlib.dll

I need it to give me back a positive number just over 0 and below 95我需要它给我返回一个大于 0 且小于 95 的正数

It throws an exception because the value of a is invalid.它抛出异常,因为a的值无效。 ulong means Unsigned Long — it doesn't accept negative numbers. ulong表示 Unsigned Long — 它不接受负数。 And value 897324782938287523942985 is too big for all integer types in C# .值 897324782938287523942985对于 C# 中的所有 integer 类型来说太大了

UPDATE : a should be of type double .更新a应该是double类型。 Firstly, it accepts negative numbers, and secondly, it accepts very big values — 897324782938287523942985 is valid for it.首先,它接受负数,其次,它接受非常大的值——897324782938287523942985 对它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM