Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.60/5 (3 votes)
See more:
Hi All,

Following condition throw input invalid format error if workflowProperties.Item[strACQCost].ToString()is decimal number and FACommon.TotalACQCost is 300000

C#
if (Convert.ToInt32(workflowProperties.Item[strACQCost].ToString()) >= Convert.ToInt32(FACommon.TotalACQCost))


How should i change my code to accept decimal and round number for workflowProperties.Item[strACQCost].ToString() so i can compare with integer?
Posted
Updated 16-Feb-14 20:14pm
v2
Comments
Malli_S 17-Feb-14 2:33am    
Use Math.Round().

http://msdn.microsoft.com/en-us/library/system.math.round.aspx

1 solution

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:
C#
if (Math.Round(Convert.ToDecimal(workflowProperties.Item[strACQCost].ToString())) >= Math.Round(Convert.ToDecimal(FACommon.TotalACQCost)))

or use Convert.ToDouble() instead of Convert.ToDecimal()

[Edit]
If the FACommon.TotalACQCost is guaranteed to always be the representation of an integer, then it can remain Convert.ToInt32():
C#
if (Math.Round(Convert.ToDecimal(workflowProperties.Item[strACQCost].ToString())) >= Convert.ToInt32(FACommon.TotalACQCost))

[/Edit]
 
Share this answer
 
v3

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