0

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

mplungjan
  • 169,008
  • 28
  • 173
  • 236
CK WONG
  • 71
  • 1
  • 7

1 Answers1

1

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.
}
Community
  • 1
  • 1
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56