本文介绍了值对于小数而言太大或太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
double shortfall = GetSomeNumber(); //3.3588548831176006E+29
if (shortfall > 0)
{
returnValue = Convert.ToDecimal(shortfall);
}
这会产生上述错误.
有人可以帮我吗?
推荐答案
嗯,这很不言自明.
decimal.MaxValue
是79,228,162,514,264,337,593,543,950,335-您的数字大于此数字.
decimal.MaxValue
is 79,228,162,514,264,337,593,543,950,335 - your number is bigger than this.
尽管 decimal
的精度比 double
更高,但 double
的范围更大-它可以处理非常非常大的非常非常小数字.
Although decimal
has a finer precision than double
, double
has a bigger range - it can handle very, very large and very, very small numbers.
现在,如果您能告诉我们您真正想做什么,我们可以尝试帮助您找到解决方案...混用 double
和 decimal很少是一个好主意
,说实话.
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.
这篇关于值对于小数而言太大或太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!