Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
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 4 years ago · Juan Pablo Isaza
2 answers
Answer question

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 4 years ago · Juan Pablo Isaza Report

0

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

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!