Engine isn't evaluating my formula

Mar 30, 2009 at 9:17 AM
Edited Apr 1, 2009 at 5:23 PM

 

 

 

Hi,

Awesome library!

I'm having a problem evaluating a formula with specified variables though.

This is the code:

CalculationEngine engine = new CalculationEngine ( );

 

ExpressionContext context = new ExpressionContext ( );

VariableCollection variables = context.Variables;

context.Imports.AddType ( typeof ( Math ) );

variables.Add ( "P", 20000 );

variables.Add ( "A", 0.169 );

variables.Add ( "T", 60 );

engine.Add ( "result", "(P*(((1+A)^(1/12))-1))/(1-(1+(((1+A)^(1/12))-1))^(-1*T))", context );

Double result = engine.GetResult<Double> ( "result" );

this.textBoxOutput.Text = result.ToString ( );

The formula functions perfectly in microsoft excel but not in the above code snippet.  Is it something wrong with my code or formula?

 

 

 

 

 

 

Mar 30, 2009 at 11:17 AM
In addition,

if I pull out part of the formula and evaluate separatly:

"CalculationEngine engine = new CalculationEngine ( );
ExpressionContext context = new ExpressionContext ( );
VariableCollection variables = context.Variables;

variables.Add ( "P", 20000.0 );
variables.Add ( "A", 0.169 );
variables.Add ( "T", 60.0 );

engine.Add ( "Z", "((1+A)^(1/12))", context );
this.textBoxOutput.Text = engine.GetResult ( "Z" ).ToString ( );"

... The output is "1" when I expect "1.01309742".

Am I doing something wrong?

Mar 30, 2009 at 11:42 AM
Edited Mar 30, 2009 at 11:54 AM
Hi,

solved the problem I was having by adding the following:

context.Options.IntegersAsDoubles = true;

Apologies for any inconvenience caused.

Cheers!