整数和十进制转换 [英] Interger and decimal conversion
问题描述
大家好,
如果workflowProperties.Item [strACQCost] .ToString()是十进制数并且FACommon.TotalACQCost是300000,则以下条件抛出输入无效格式错误
Hi All,
Following condition throw input invalid format error if workflowProperties.Item[strACQCost].ToString()is decimal number and FACommon.TotalACQCost is 300000
if (Convert.ToInt32(workflowProperties.Item[strACQCost].ToString()) >= Convert.ToInt32(FACommon.TotalACQCost))
如何更改我的代码以接受workflowProperties.Item [strACQCost] .ToString()的十进制和整数,以便我可以与整数进行比较?
How should i change my code to accept decimal and round number for workflowProperties.Item[strACQCost].ToString() so i can compare with integer?
推荐答案
什么是的实际数据类型 workflowProperties.Item [strACQCost]
和FACommon.TotalACQCost
?
(不他们代表什么类型。)
我要去猜workflowProperties.Item [strACQCost]
是object
和FACommon.TotalACQCost
是一个字符串
。
如果是这种情况,则需要将它们转换为与可能所包含的数据一致的类型。
如果其中任何一个可以是实数(即,不限于整数值,我认为你的意思是十进制),
那么它们应该是转换为类型十进制
(或double
),然后舍入值进行比较:
What are the actual data types ofworkflowProperties.Item[strACQCost]
andFACommon.TotalACQCost
?
(Not what types do they represent.)
I'm going to guess thatworkflowProperties.Item[strACQCost]
isobject
andFACommon.TotalACQCost
is astring
.
If that's the case, then they need to be converted to types consistent with the data they could contain.
If either could be a real number (i.e., not restricted to integer values, what I think you mean when you say "decimal"),
then they should be converted to typedecimal
(ordouble
) and then round the values for your comparison:
if (Math.Round(Convert.ToDecimal(workflowProperties.Item[strACQCost].ToString())) >= Math.Round(Convert.ToDecimal(FACommon.TotalACQCost)))
或使用转换.ToDouble()
而不是 Convert.ToDecimal()
如果 FACommon.TotalACQCost
保证到总是是整数的表示,然后它可以保持 Convert.ToInt32()
:
or use Convert.ToDouble()
instead of Convert.ToDecimal()
If the FACommon.TotalACQCost
is guaranteed to always be the representation of an integer, then it can remain Convert.ToInt32()
:
if (Math.Round(Convert.ToDecimal(workflowProperties.Item[strACQCost].ToString())) >= Convert.ToInt32(FACommon.TotalACQCost))
[/ Edit]
[/Edit]
这篇关于整数和十进制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!