Skip to content

Instantly share code, notes, and snippets.

@whatgoodisaroad
Created July 10, 2011 02:13
Show Gist options
  • Select an option

  • Save whatgoodisaroad/1074167 to your computer and use it in GitHub Desktop.

Select an option

Save whatgoodisaroad/1074167 to your computer and use it in GitHub Desktop.
Big numbers can store any number of significant figures
// Creating a Big object is easy, simply pass the number you want
// as a string argument to the constructor.
var myBig = new Big("2.00000000000000000000000000000000000001");
// When we want to see its value, all digits are preserved.
myBig.toString();
// = "2.00000000000000000000000000000000000001"
// When doing math on Big objects, the digits are preserved
// and the result is another Big object.
myBig.times(new Big("2")).toString();
// = "4.00000000000000000000000000000000000002"
// We can store large, numbers like these digits of PI:
var pi = new Big("3.1415926535897932384626433832795028841971693993751058209749445923078164062");
pi.toString();
// = "3.1415926535897932384626433832795028841971693993751058209749445923078164062"
pi.times(new Big("2")).toString();
// = "6.2831853071795864769252867665590057683943387987502116419498891846156328124"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment