简体   繁体   English

十进制的值太大或太小

[英]Value was either too large or too small for a Decimal

I have the following piece of code:我有以下一段代码:

double shortfall = GetSomeNumber(); //3.3588548831176006E+29

if (shortfall > 0)
{
  returnValue = Convert.ToDecimal(shortfall);
}

That generates the above error.这会产生上述错误。

Well, it's fairly self-explanatory.嗯,这是不言自明的。

decimal.MaxValue is 79,228,162,514,264,337,593,543,950,335 - your number is bigger than this. decimal.MaxValue是 79,228,162,514,264,337,593,543,950,335 - 你的数字比这个大。

Although decimal has a finer precision than double , double has a bigger range - it can handle very, very large and very, very small numbers.尽管decimal的精度比double更好,但double的范围更大——它可以处理非常非常大和非常非常小的数字。

Now, if you could tell us what you're really trying to do, we could try to help find a solution... it's rarely a good idea to mix double and decimal , to be honest.现在,如果您能告诉我们您真正想要做什么,我们可以尝试帮助找到解决方案……说实话,混合使用doubledecimal很少是一个好主意。

It means that the value returned cannot be converted to decimal as it is too large.这意味着返回的值太大,无法转换为十进制。

Decimal values can be between positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335 - see MSDN . 十进制值可以介于正 79,228,162,514,264,337,593,543,950,335 到负 79,228,162,514,264,337,593,543,950,335 之间 - 请参阅MSDN

Double can handle much larger numbers - negative 1.79769313486232e308 to positive 1.79769313486232e308. Double可以处理更大的数字 - 负 1.79769313486232e308 到正 1.79769313486232e308。 These will not all be convertible to Decimal.这些不会全部转换为十进制。

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

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