Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert a string to decimal when the string contains an arithmetic expression?

Such as,
C#
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.

It isn't straight forward, but CP is here to help[]
 
Share this answer
 
Comments
Venkatesh Mookkan 2-May-11 6:24am    
Good answer!
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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900