Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:01:56+00:00 2026-06-06T18:01:56+00:00

I am currently using ncalc library to do several evaluation and get the result

  • 0

I am currently using ncalc library to do several evaluation and get the result out of it.

Right now I have found a problem where if I have a price in the format “1,234.01” it will fail to evaluate my expression.

The current workaround I’ve used was to remove the , but I was wondering if there is way to evaluate a currency without having to remove the , for example:

decimal price = 0;
if (!decimal.TryParse(iPrice.Text, out price))
{
    MessageBox.Show("Price is not formatted correctly...");
    return;
}

decimal currency = 0;
if (!decimal.TryParse(iCurrency.Text, out currency))
{
    MessageBox.Show("Currency is not formatted correctly...");
    return;
}

string formula = iFormula.Text.Replace("Price", price.ToString("n2")).Replace("Currency", currency.ToString("n2"));
Expression exp = new Expression(formula);
exp.Evaluate();

Evaluate fails because of the , from my price where if I remove it, it works just fine.

Sample of the formula:

(((Price+12,9)+((Price+12,9)*0,05)+(((Price+12,9)+((Price+12,9)*0,05))*0,029)+0,45)*Currency)

Stacktrace as requested:

NCalc.EvaluationException was unhandled
  Message=mismatched input ',' expecting ')' at line 1:4
mismatched input ',' expecting ')' at line 1:20
mismatched input ',' expecting ')' at line 1:43
mismatched input ',' expecting ')' at line 1:59
missing EOF at ')' at line 1:77
  Source=NCalc
  StackTrace:
       at NCalc.Expression.Evaluate()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:02:01+00:00Added an answer on June 6, 2026 at 6:02 pm

    Your question is still unclear to me, but I suspect you can fix this just by changing the format you’re using when replacing. Change this:

    string formula = iFormula.Text.Replace("Price", price.ToString("n2")) 
                                  .Replace("Currency", currency.ToString("n2"));
    

    to this:

    string formula = iFormula.Text.Replace("Price", price.ToString("f2")) 
                                  .Replace("Currency", currency.ToString("f2"));
    

    That will use the “fixed point” format instead of the “number” format. You won’t get grouping. Note that grouping isn’t part of the number itself – it’s part of how you format a number.

    I’d also be tempted to specify the invariant culture explicitly, by the way.

    As an aside: I haven’t used NCalc myself, but if it’s really forcing you to specify the numeric values in an expression as text, that sounds pretty poor. I’d expect some sort of parameterization (as per most SQL providers, for example) which should make all of this go away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I currently using transactional replication with updatable subscription. Is there any ways
I am currently using Windows Server 2008 Standard and have several Hyper V machines.
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I am currently using matplotlib.pyplot to create graphs and would like to have the
Currently using ColdFusion 8 enterprise on 32 bit linux box to send out our
Im currently using the Barcode Scanner from the open source library Zxing in my
Note: Currently using Perforce as a CM tool. I currently do several debug releases
I am currently using TopShelf with Ninject to create a Windows Service. I have
Currently using Chrome v19.0.1084.46 (Official Build 135956) beta-m jqGrid 4.3.2 (latest release) The problem
im currently using the SDL-devel-1.2.13-mingw32 library in code blocks 8.02. with the mingw 5.1.6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.