简体   繁体   English

应用脚本电子表格的浮动计算,Google应用脚本可以进行浮点数计算吗?

[英]App script spreadsheets float calculation, can google app script do float point number calc?

Can google app script use external library in google app script that can do float number calculation, like bigdecimal? Google App脚本可以在Google App脚本中使用外部库来进行浮点数计算吗,例如bigdecimal?

when I do 当我做

 var i = 1.15 - 1.12 console.log(i); 

then i = 0.029999999999999805 那么i = 0.029999999999999805

Just to answer the question if it's possible, the answer is Yes, based on this SO post . 根据此SO post ,仅回答可能的问题,答案是肯定

However if you wanted to round it up to 2 decimal places only (or more), you don't have to resort to external library, use Math.round : 但是,如果您只想将其舍入到小数点后两位(或更多),则不必诉诸外部库,请使用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.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM