App script 电子表格浮点数计算,google app script 可以做浮点数计算器吗?
App script spreadsheets float calculation, can google app script do float point number calc?
google 应用程序脚本可以在 google 应用程序脚本中使用可以进行浮点数计算的外部库,例如 bigdecimal?
当我
var i = 1.15 - 1.12
console.log(i);
然后 i = 0.029999999999999805
只是回答这个问题是否可能,答案是肯定的,基于此SO post。
然而,如果你只想将它四舍五入到小数点后两位(或更多),你不必求助于外部库,使用 Math.round:
function floatNumber(){
var myInt = 1.15 - 1.12 ;
myInt = Math.round(myInt * 100) / 100;
Logger.log(myInt);
//output 0.03
//if you want 3 decimal places use /1000, and so on.
}
google 应用程序脚本可以在 google 应用程序脚本中使用可以进行浮点数计算的外部库,例如 bigdecimal?
当我
var i = 1.15 - 1.12
console.log(i);
然后 i = 0.029999999999999805
只是回答这个问题是否可能,答案是肯定的,基于此SO post。
然而,如果你只想将它四舍五入到小数点后两位(或更多),你不必求助于外部库,使用 Math.round:
function floatNumber(){
var myInt = 1.15 - 1.12 ;
myInt = Math.round(myInt * 100) / 100;
Logger.log(myInt);
//output 0.03
//if you want 3 decimal places use /1000, and so on.
}