是否有小数计算出库,特别是战俘(十进制小数)
的方法?我找不到任何。
它可以是游离的或商业的,无论哪种方式,只要有一个。
注:我不能做我自己,不能用for循环,不能使用 Math.Pow
, Math.Exp
或将Math.log
,因为他们都采取双
S,而我不能使用双
秒。我不能用一个意甲,因为它会为precise为双
秒。
其中multipliyers的是速度:1 /速度^(天/ 365)。
原因没有小数幂函数是因为这将是毫无意义的使用十进制
该计算。使用双
。
记住,小数的一点是要确保您获得精确的算法上可能的完全的再presented为的短的十进制数的值。对于率合理值
和天
,任何其他SUBEX pressions值明显的不是的将是完全重新presented短十进制值。你将要处理的不精确值,所以使用专为稍微不精确值的快速计算一个类型,如双。
在双打中计算得出的结果会通过一个便士的一种方式或其他几十亿分处于关机状态。谁在乎? 您稍后将轮出误差。执行率计算双打。一旦你有一个结果是需要重新变回货币,一万个相乘的结果,其舍入到最接近的整数,将其转换为十进制,然后再除以它由一万,你'将有一个结果精确到小数点后四位,这应该是足够的财务核算。
Is there a library for decimal calculation, especially the Pow(decimal, decimal)
method? I can't find any.
It can be free or commercial, either way, as long as there is one.
Note: I can't do it myself, can't use for loops, can't use Math.Pow
, Math.Exp
or Math.Log
, because they all take double
s, and I can't use double
s. I can't use a serie because it would be as precise as double
s.
One of the multipliyers is a rate : 1/rate^(days/365).
The reason there is no decimal power function is because it would be pointless to use decimal
for that calculation. Use double
.
Remember, the point of decimal is to ensure that you get exact arithmetic on values that can be exactly represented as short decimal numbers. For reasonable values of rate
and days
, the values of any of the other subexpressions are clearly not going to be exactly represented as short decimal values. You're going to be dealing with inexact values, so use a type designed for fast calculations of slightly inexact values, like double.
The results when computed in doubles are going to be off by a few billionths of a penny one way or the other. Who cares? You'll round out the error later. Do the rate calculation in doubles. Once you have a result that needs to be turned back into a currency again, multiply the result by ten thousand, round it off to the nearest integer, convert that to a decimal, and then divide it out by ten thousand again, and you'll have a result accurate to four decimal places, which ought to be plenty for a financial calculation.
上一篇:WPF - 我怎样才能使一个刷子绘制图的纸状的广场?刷子、能使、广场、WPF
下一篇:如何生成的xs:日期在WCF OperationContract的参数参数、日期、xs、OperationContract