谷歌应用脚本可以使用谷歌应用脚本中的外部库来做浮点数计算,比如大十进制?
当我这样做时
var i = 1.15 - 1.12
console.log(i);
然后i = 0.029999999999999805
只是为了回答这个问题,如果可能的话,答案是肯定的,基于这个 SO 帖子。
但是,如果您只想将其四舍五入到小数点后 2 位(或更多(,则不必求助于外部库,请使用 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.
}