Reputation: 119
I have a JSON response from a REST post. Now I want to get the sum of a field.
restResponse*.amount.sum()
But the amount field is a string so it just concatenats those strings ...
Is there a way to convert the strings 'on the fly' to float or double for .sum()?
Upvotes: 0
Views: 705
Reputation: 853
Try as below :-
//sum in integer
restResponse*.amount*.toInteger().sum()
//sum in double
restResponse*.amount*.toDouble().sum()
//sum in float
restResponse*.amount*.toFloat().sum()
Hope it will help you...:)
Upvotes: 2