Hier in diesem Code, mag ich die Summe von bestimmten Daten zu berechnen erreichen, die ich aus Excel-Datei von dieser Linie nahm:wie zuweisen JSON.stringify(), um JavaScript-Variable
" sumofKoli += JSON.stringify(row.values[4]);".
Mein Problem ist, dass selbst diese Codezeile:
console.log(JSON.stringify(row.values[3])+" Sold number of :"+ JSON.stringify(row.values[4]));
Gibt, was ich will wie "47", die ich genau als eine ganze Zahl will, wenn ich versuche, alle Daten zu summieren, ich habe ein Ergebnis, das wie "94559129995555.5.2556149.9" ist. Es fügt es als ein Zeichenfolgenwert hinzu, ich möchte es als Ganzzahl summieren. Kannst du mir helfen ? Hier
ist der vollständige Code:
Reader.prototype.readExcel = function(chartType,callback){
// read from a file
var workbook = new Excel.Workbook();
var sumofKoli=0;
var sumPrice =0;
workbook.xlsx.readFile(filename)
.then(function(err,results) {
var worksheet = workbook.getWorksheet('Sayfa1');
worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
console.log("----------");
console.log(JSON.stringify(row.values[3])+" Sold number of :"+ JSON.stringify(row.values[4]));
console.log("----------");
sumofKoli += JSON.stringify(row.values[4]);
console.log(JSON.stringify(row.values[3])+" Sold in price of :"+ JSON.stringify(row.values[5]));
sumPrice += JSON.stringify(row.values[5]);
console.log("----------");
});
results = { sumofKoli : sumofKoli, sumTutar : sumPrice};
if (err){callback(err,null);}
callback(null,results);
});
Sie versuchen, eine Variable vom Typ 'string' mit einer Variablen vom Typ 'integer' hinzuzufügen. –