Formula Casteo Decimal asp.net

0

Good afternoon:

I'm making a Nominal Rate formula for that they gave me this formula:

= (((TEA + 1) ^ (1/12)) - 1) * 12

decimal x = 3.141592654M ; 
double pi = (double) x ;

dtorequest.Tasa = Convert.ToDecimal((Math.Pow((Convert.ToDecimal(pi) + 1), (1 / 12))) - 1) * 12;//40;

Since my dtorequest.Tasa is a decimal variable, I get a decimal error. Could you help me please?

An example:

    
asked by PieroDev 09.06.2017 в 00:59
source

2 answers

0

The error that comes out of Overflow when casting is because the Decimal is bigger than the Double can represent.

On the other hand, unless you are doing a graph with some curve, it sounds strange to me that the PI number is in a Financial formula:)

    
answered by 09.06.2017 в 01:34
0

You do not need to define your own pi but instead use it:

Math.PI

Also in the following expression (1/12) you should use a 1.0 which is a double otherwise it will be a whole division and the result will not be as expected

The complete line would be

dtorequest.Tasa = Convert.ToDecimal((Math.Pow((Math.PI + 1),(1.0/12)) - 1) * 12)
    
answered by 09.06.2017 в 01:34