14,640,679 members
Rate this:
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
Malli_S 17-Feb-14 2:33am

Use Math.Round().

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

Rate this:

## 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()`

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