Support > Forums > OpenBots Studio > Convert String to Integer
Dear Team,
I have the Amount value in the Datarow and I would like to check if the Amount value column has less than value or not.
I'm trying to convert the string to integer but getting the below error. Convert.ToInt32(vSet)<0 vSet value is "-16.500" Error Occurred at Line 8: If (Convert.ToInt32(vSet)<0) - [Source: 'C:\Users\Faheem786\Documents\OpenBots Studio\OB Scripts\ComapringExcelData\Main.obscript', Type: 'FormatException', Message: 'Input string was not in a correct format.']
Could you please help me on this?
This forum has 317 topics, 687 replies, and was last updated 5 months ago by Nataly Alvarado...
Thank you for your quick response. I really appreciate it and it resolves my issue.
Hi Syed Faheem,
I hope this message finds you well. I understand that you are encountering an error while attempting to convert the amount value in the DataRow. The issue lies in trying to convert a decimal string ("-16.500") directly to an integer, which is causing a FormatException.
In the Studio engine, C# rules are followed, and integer variables don't support decimals or fractions, only whole numbers. To address this, I recommend using a Decimal or Double variable to store the converted number using either Convert.ToDouble or Convert.ToDecimal. Specifically, in your case, using Convert.ToDecimal is advisable, especially when dealing with monetary amounts, as it provides greater numeric precision.
Best regards, Support Team
You are not authorized to reply, please click here to login and add your reply to this topic.