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
  • 155,085
  • 27
  • 166
  • 222
CK WONG
  • 61
  • 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
noogui
  • 16,300
  • 4
  • 25
  • 51