Input String was not in a correct format String to Int

Variable1 = row.Item(3).ToString

Variable1 contains "17,757.00"

Variable1 = Variable1.Replace(",","")

This step gives me the error:
Variable2 = convert.ToInt32(Variable1)
image

Variable2 is of type Int32.

@atomic

an int cannot contain a dot. Via a double this value can be converted into an int.
Have a look below

grafik

on last line take a note on the out of the box roundings

2 Likes

you have decimal places in string, int does not have decimail places.

either convert to decimal or remove .00 from string

1 Like

@ppr @TimK Thank you both, I added one extra step:

Variable1 = row.Item(3).ToString

Variable1 contains “17,757.00”

Variable1 = Variable1.Replace(",","")

VariableDec = convert.ToDecimal(Variable1) <--- 

Variable2 = convert.ToInt32(VariableDec)

Hello,

The output for the your problem would be

String Variable1 = “17757.00”

Cint(Convert.ToDouble(Variable1)) = 17757

After conversion into an Integer Decimal number will be removed.

1 Like