整数和十进制转换

编程入门 行业动态 更新时间:2024-10-18 01:34:57
本文介绍了整数和十进制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 如果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]

更多推荐

整数和十进制转换

本文发布于:2023-10-24 20:09:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!