Click here to Skip to main content
14,542,196 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to convert a string to decimal when the string contains an arithmetic expression?

Such as,
string str ="((1024+34)-(8*56)";


Please suggest




The convert.todecimal won't work because of the presence of parenthesis(,)
Ex:-
string str = ((((@accijns+@ecotax)/100) * @unit) +@fostplus)
I am replacing @accijns, etc by property value

below is my code

string strFormula = oPriceType.formula;
//(formula is like ((((@accijns+@ecotax)/100) * @unit) +@fostplus)
string strCalculation = strFormula.Replace("@accijns", accijnValue.ToString()).Replace("@fostplus", fostplusValue.ToString()).Replace("@cost_price", @cost_price.ToString())
.Replace("@cost_extra", @cost_extra.ToString()).Replace("@cost_fob", @cost_fob.ToString()).Replace("@cost_ship", @cost_ship.ToString()).Replace("@cost_warehouse", @cost_warehouse.ToString())
.Replace("@ecotax", ecotaxValue.ToString()).Replace("@unit", @unit.ToString()).Replace("@discount_extra", @discount_extra.ToString()).Replace("@discount_payterm", @discount_payterm.ToString())
.Replace("@discount_financial", @discount_financial.ToString()).Replace("@weight", @weight.ToString()).Replace("@import_duty", @import_duty.ToString()).Replace("@degree", @degree.ToString())
.Replace("@recom_price", @recom_price.ToString());


have you got the idea now??
please suggest
thank you
sandeep
Posted
Updated 2-May-11 2:05am
v5
Comments
Sandeep Mewara 2-May-11 6:18am
   
Not clear what you are trying here.
Rate this:
Please Sign up or sign in to vote.

Solution 1

It isn't straight forward, but CP is here to help[]
   
Comments
Venkatesh Mookkan 2-May-11 6:24am
   
Good answer!
Rate this:
Please Sign up or sign in to vote.

Solution 3

Take a look at the link Nagy Vilmos provided - it's a fine article :thumbsup:.

And in case you're interested in creating your own solution from scratch, here's something to get you started:
Reverse Polish notation[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100