can't accumulate currency values of records in a variable

can't accumulate currency values of records in a variable

hi all. Im trying to add all the currency entries of a field in a single value. I wrote this:

total = 0.0;
records = Transactions [Type_of_Transaction == "Earnings"];
for each x in records
{
total = x.amount;
}
input.Total_field = total;


when I access the app, the Total_field shows 0.0 ; it doesn't add up to the variable. At some point, when tweaking the code it gave me an error that the "total" variable was float, and the currency value was long, and therefore the sum operation wasnt possible. Hope for an answer soon, thanks in advance.