I've written a code that pretty much does what I need it to do, which is compare values on different spreadsheets and, if they're have the same info, add up their values, but I noticed the numbers are behaving as strings, which means, 4 1 is giving me 41 not 5. Is it because of the way I wrote the code or is there any way to fix it? The rest of the code is pretty much just me calling columns on the spreadsheet, important part is:
for (let i =0; i<tamanho; i ){
for (let c=0; c<tamanhodenomes; c ) {
if (vendidos[i][0] == nomes[c][0]){
totalvendido[c][0] =quantidadevendida[i][0]
console.log(totalvendido)
}
CodePudding user response:
for (let i =0; i<tamanho; i ){
for (let c=0; c<tamanhodenomes; c ) {
if (vendidos[i][0] == nomes[c][0]){
totalvendido[c][0] =Number(quantidadevendida[i][0]);
console.log(totalvendido)
}
CodePudding user response:
I've used parseInt() in this situation, so:
for (let i =0; i<tamanho; i ){
for (let c=0; c<tamanhodenomes; c ) {
if (vendidos[i][0] == nomes[c][0]){
totalvendido[c][0] = parseInt(totalvendido[c][0]) parseInt(quantidadevendida[i][0])
console.log(totalvendido)
}