Skip to content

Instantly share code, notes, and snippets.

@whatgoodisaroad
Created July 10, 2011 01:57
Show Gist options
  • Select an option

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

Select an option

Save whatgoodisaroad/1074157 to your computer and use it in GitHub Desktop.
JavaScript Primitive Numbers have Fixed Precision
// Numbers with many significant figures may be truncated:
var primitive = 2.00000000000000000000000000000000000001;
// Immediately after creation, the low digits are truncated away.
primitive;
// = 2
// Performing math on primitives will not include truncated digits.
primitive * 2;
// = 4
// In the case of PI, only 16 digits are preserved.
var pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062; // ...
pi;
// = 3.141592653589793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment