0

Is there a way to divide a decimal by another decimal in Ncalc?

When I try

Expression exp = new Expression("119 / 1.19");
    try
    {
        MessageBox.Show(exp.Evaluate().ToString());
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "ERROR");
    }

I get:

"Operator '/' can't be applied to operands of type 'decimal' and 'double'".

Ron Beyer
  • 11,003
  • 1
  • 19
  • 37
ComanderKai77
  • 460
  • 6
  • 14
  • Unable to reproduce. Got 100 in MessageBox. What version of Ncalc? – Steve Nov 06 '15 at 22:31
  • Are you sure that this is the code that errors out? Looks like you are dividing an integer and a double, not two decimals, and your error code says a double and a decimal, I'm confused on where the error actually is. – Ron Beyer Nov 06 '15 at 22:32
  • I've cleaned my project and now is it working. Strange – ComanderKai77 Nov 06 '15 at 22:45

1 Answers1

1

Use System.Double

Like this

System.Double amount = 11000.19;
Expression ex = new Expression("Amount*0.2");
ex.Parameters.Add("Amount", amount);
object result = ex.Evaluate();
saurabh
  • 6,687
  • 7
  • 42
  • 63