Support > Forums > OpenBots Studio > Convert String to Integer

Convert String to Integer

Syed Faheem

  • Reporter
  • Calender Icon January 10,2024 at 3:55 PM

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 314 topics, 681 replies, and was last updated 24 days ago by Support Agent

Syed Faheem

  • Participant
  • Calender Icon January 26,2024 at 6:29 PM

Thank you for your quick response. I really appreciate it and it resolves my issue.

Nataly Alvarado...

  • Participant
  • Calender Icon January 10,2024 at 7:11 PM

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.