Google Spreadsheet Script getValues - 强制int而不是字符串 [英] Google Spreadsheet Script getValues - Force int instead of string
问题描述
或者是唯一的解决方案,获取数组,然后parseInt整个数组在循环?
使用一元运算符'+'可以很容易地做到这一点,如下所示:首先使用 getValue()
或 getValues()$>从电子表格中获取值C $ C>。假设你有两个这样的值,并将它们存储在
之外的任何数学二元运算符来强制它们被识别为数字,这会连接字符串,所以 A = 1
和 B = 2
中。你可以使用除< A - B = -1
,而 A + B
将返回'12'。
您可以强制变量通过使用 +
一元运算符以及任何可能被解释为字符串的变量来简化数字。例如, + A + + B
将返回正确的3。
Is there a way to force .getRange().getValues() to return an int? Although only numbers exist in my range, it is returning them as strings. I would like to avoid using parseInt in every one of my statements or creating a separate array with converted values.
Or is that the only solution, to get the array and then parseInt the entire array in a loop?
you can do this easily using the unary '+' operator as follows:
First get your values from your spreadsheet using getValue()
or getValues()
. Suppose you get two such values, and store them in A = 1
and B = 2
. You can force them to be recognized as numbers by using any math binary operator except for +
, which concatenates strings, so A - B = -1
, while A + B
will return '12'.
You can force the variables to be numbers simply by using the +
unary operator with any variable that might be interpreted as a string. For example, +A + +B
will return the correct value of 3.
这篇关于Google Spreadsheet Script getValues - 强制int而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!