2

All numbers are changed to floats, with a .0 concatenated to the end.

I have tried parseInt, toFixed, round, floor and every other obvious choice.

A simple example:

Logger.log(list.length);

the log shows float values of type "Number" with a value of 5.0 for the length.

Any attempt to add numbers results in the same

for (i in [1,2,3,4,5]) {
  count++;
  Logger.log(count);
}

The log still shows float values

I would expect Array.length to return an integer

2 Answers2

1

Take a look at this answer it explains how the Number data type works in JavaScript (Google Apps Scripts are based on JS). If you need to display just the number before the decimal point, I would suggest using toString() and then substring() to handle it as a String, this would look something like this:

var numStr = count.toString()
var toDisplay = numStr.substr(0,numStr.indexOf("."));
Logger.log(toDisplay);

Then to use it as a number again you could use Number(toDisplay) (Documentation here)

AMolina
  • 1,355
  • 1
  • 7
  • 17
0

Try the following:

function toInteger(val){
    val = parseInt(val);    // in case val is not an integer
    return val.toString()
}

function testToInteger(){
    let ar1 = [1, 2, 3.6, 4.713];
    
    Logger.log(ar1);    //  [1.0, 2.0, 3.6, 4.713]
    Logger.log(ar1.map(toInteger));    // [1, 2, 3, 4]
    Logger.log(ar1.map(toInteger)[3]);    // 4
    Logger.log(ar1.map(toInteger)[3] * 2);    // 8.0
    Logger.log(toInteger(ar1.map(toInteger)[3] * 2))    // 8
}
Tom D
  • 66
  • 5