Removing decimal from string

Viewed 62

I'm trying to understand how I can remove a decimal. I have tried Math.trunc() but it never seems to remove. Logger.log(esValues.length) prints 500.0, I tried adding var removeDecimal = Math.trunc(esValues.length) then printing removeDecimal but I still get 500.0

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var es = ss.getSheetByName("School1");
  var ms = ss.getSheetByName("School2");
  var hs = ss.getSheetByName("School3");
  var esValues = es.getDataRange().getValues();
  var counterDell = 0;
  var counterHP = 0;
  //var esValues = es.getRange('A:C').getValues();
  Logger.log(esValues.length); //This prints 500.0, Also tried adding here Logger.log(Math.trunc(esValues.length))
  for (var i = 0; i < esValues.length; i++) {
    var data = esValues[i];
    var first = data[1];
    var last = data[0];
    var middle = data[2];
    var studentid = data[3];
    var device = data[4];
    if (device.includes("Dell")) {
      counterDell++;
    } else if (device.includes("HP")) {
      counterHP++;
    }

  }
  Logger.log(`Dell count is ${counterDell}`)
  Logger.log(`Hp count is ${counterHP}`)
}
2 Answers
Logger.log(esValues.length.split('.')[0])

breaks the decimal into integer and decimal portions, then we discard the decimal portion.

Actually just not using the logger will elimate the .0. For some stupid reason it has always done that.

function lfunko() {
  var ss = SpreadsheetApp.getActive();
  var es = ss.getSheetByName("School1");
  var vs = es.getDataRange().getValues();
  var counterDell = 0;
  var counterHP =
  for (var i = 0; i < vs.length; i++) {
    var device = vs[4];
    if (device.includes("Dell")) {
      counterDell++;
    } else if (device.includes("HP")) {
      counterHP++;
    }
  }
  const msg = `HP: ${counterHP} DELL: ${counterDell}`
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(msg),"Counts");
}
Related