Calculate totals in a loop

Calculate totals in a loop

Hi,
 
I am looping through related records and trying to calculate a total for a certain field. I copied the example from  https://www.zoho.com/crm/help/automation/custom-functions-programming.html which is basically as below:

total = 0.0 ;
for each rec in resp
{
    total = (total + (rec.get("Amount")).toDecimal()) ;
}

When I run this on my CRM I get the following error: "Error evaluating NUMERIC expression :". That is all I get and I know it occurs on that line. My "Amount" field is type Currency. Would that be causing the issue?

Hope someone can help.

Thanks.