Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about big numbers #42

Open
brettlangdon opened this issue Apr 15, 2016 · 2 comments
Open

Add documentation about big numbers #42

brettlangdon opened this issue Apr 15, 2016 · 2 comments

Comments

@brettlangdon
Copy link
Owner

brettlangdon commented Apr 15, 2016

I could have sworn I had written something in the readme about it, but apparently I didn't.

For reference for anyone finding this before I actually get around to adding it to the docs:

We ran into an issue #16 which is that number values returned from Datadog were larger than JSON could support, so there was lose of precision/overflowing for large numbers.

The solution was to utilize json-bigint which utilizes bignumber.js to support larger numbers in JSON.

The problem with this is that the format that bignumber.js stores numbers in isn't the most intuitive manner.

> var bn = require('bignumber.js');
> console.dir(new bn('2349082309420934834234234'));
{ s: 1, e: 24, c: [ 23490823094, 20934834234234 ] }

For information on how to interact with bignumber.js please see their documentation: https://www.npmjs.com/package/bignumber.js

@jaredallard
Copy link

Is there a reason Datadog doesn't return string representation of these numbers? Seems like an odd choice...

@brettlangdon
Copy link
Owner Author

Hard to know for sure, my best guess is for backwards compatibility, since they have always been numbers, and are stored as numbers on their end. The numbers are actually fine, if you can parse an int64.

We could probably coerce the ids into strings here in this library, but we'd probably still have to use json-bigint for parsing first anyways.

¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants