Prevously I had a result from a Database Connection SQL statement that resembled the following:
[{"BALANCE":111.11},{"BALANCE":222.12},{"BALANCE":444.30}]
And I used the following contents of an expression node to calculate the sum:
sum = 0;
foreach (row : message.payload) {
sum += row['BALANCE'];
}
message.payload = sum;
This did not quite work out, but notice below that there are no quotes around the numeric variable that was returned
777.5299999999999994315658113919199
From an excellent answer from a previous thread, I switched to the following expression node contents:
sum = 0;
foreach (row : message.payload) {
sum += row['BALANCE'];
}
message.payload = new java.text.DecimalFormat("#.##").format(sum);
This resulted the accurate result below:
"777.53"
My only problem is that it has quotes around the number. How can I eliminate the quotes?
Thanks