简体   繁体   中英

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?

when I do

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

then i = 0.029999999999999805

Just to answer the question if it's possible, the answer is Yes, based on this 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 :

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.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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