• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

102
Vistas
Removing decimal from string

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}`)
}
about 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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");
}
about 3 years ago · Juan Pablo Isaza Denunciar

0

Logger.log(esValues.length.split('.')[0])

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

about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda