整数和十进制转换 [英] Interger and decimal conversion

查看:115
本文介绍了整数和十进制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如果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 of workflowProperties.Item[strACQCost] and FACommon.TotalACQCost ?
(Not what types do they represent.)
I'm going to guess that workflowProperties.Item[strACQCost] is object and FACommon.TotalACQCost is a string.
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 type decimal (or double) 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆