Method - Calculation

I'm trying to calculate the following fields:

quantity_requested = Integer

cost = Decimal

I seem to have a problem with the COST field. The error is "Input string was not in a correct format."

int w = (Int32.Parse(plist_h.getProperty("quantity_requested")) * Convert.ToInt32(hdPart.getProperty("cost")));

Parents
  • Hello,

    The issue that you're running into is that decimal properties such as Cost comes in a format like "38.49". Decimal values like this cannot be stored in Integers using C# or VB, so you would need to use a Float or a Double instead. Building off of that, when you multiply an integer and a double in C#, the result is a double, so you would also need to update the type of the variable storing this result. Try using the code sample below.

    double w = (Int32.Parse(plist_h.getProperty("quantity_requested")) * Convert.ToDouble(hdPart.getProperty("cost")));


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

Reply
  • Hello,

    The issue that you're running into is that decimal properties such as Cost comes in a format like "38.49". Decimal values like this cannot be stored in Integers using C# or VB, so you would need to use a Float or a Double instead. Building off of that, when you multiply an integer and a double in C#, the result is a double, so you would also need to update the type of the variable storing this result. Try using the code sample below.

    double w = (Int32.Parse(plist_h.getProperty("quantity_requested")) * Convert.ToDouble(hdPart.getProperty("cost")));


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

Children
No Data