Click here to Skip to main content
14,599,199 members
Rate this:
Please Sign up or sign in to vote.
See more:
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))


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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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)))

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

[/Edit]
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100