-1
I have a code with Datatable and wanted to group and add values in situations
var table = $('#tabelaDadosFinanc').DataTable();
var data = table
.rows()
.data();
var total = 0;
for (var i = 0; i < data.length; i++){
var valor = data[i]['valor'];
var moeda = data[i]['moeda'];
removeFirst = valor.replace('<span class="text-danger" id="negativo">','');
valores = removeFirst.replace('</span>','');
a = valores.replace('.','');
b = a.replace(',', '.')
total +=parseFloat(b);
}
console.log(total);
You would need to Group by currency type and add up the values,
ex: as I have today
Moeda | Valor
Real | -56,12
Real | -48,54
AU | -46,60
Real | -46,60
Real | -46,60
Real | 46,60
Real | 48,54
Real | 56,12
to look like this at the end
Real| -46,60
AU | -46,60
You will consider currency and name?
– Felipe Avelar
consider first the currency - and group the values belonging to the currency ex: Real -> -46,60 AU -> -46,60
– Bitencorp
The values at the end of the grouping are not those for example Real | will give another value?
– novic
the value of the grouping is the sum of the values, total of real, total of Au
– Bitencorp
But Real is different from R$ which, in turn, is different from RS. The doubt is, Real, R$ and RS are the same thing?
– Felipe Avelar
Yes they are the same things
– Bitencorp
Felipe, just a doubt how to convert this (var value = date[i]['value']; var currency = date[i]['currency'];) to const date = [ {"currency": "Real", "value":-56.12}, {"currency": "Real", "value":-48.54}, {"currency": "AU", "value":-46.60}, {"currency": "Real", "value":-46.60}, {"currency": "Real", "value":-46.60}, {"currency": "Real", "value":46.60}, {"currency": "Real", "value":":48.54}, {"currency": "Real", "value":56.12 } ];
– Bitencorp