字符串到十进制的转换 [英] string to decimal conversion
本文介绍了字符串到十进制的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当字符串包含算术表达式时如何将其转换为十进制?
如,
How to convert a string to decimal when the string contains an arithmetic expression?
Such as,
string str ="((1024+34)-(8*56)";
请提出
由于存在括号(,),因此convert.todecimal无法使用
例如:-
字符串str =(((((@ accijns + @ ecotax)/100)* @unit)+ @ fostplus)
我将@accijns等替换为属性值
以下是我的代码
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());
你现在有了主意吗?
请提出
谢谢
sandeep
have you got the idea now??
please suggest
thank you
sandeep
推荐答案
这不是直截了当的,但是CP是 ]
It isn''t straight forward, but CP is here to help[]
看看Nagy Vilmos提供的链接-这是一篇很好的文章:thumbsup :.
如果您有兴趣从头开始创建自己的解决方案,可以通过以下方法入门:
反波兰符号 [
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[^]
这篇关于字符串到十进制的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文