4

When I try to convert a bigint passed from php, into a integer in nodejs, the result is always different, I couldn't figure out what's wrong with it.

> var a = parseInt('135601920000000040', 10);
undefined
> a
135601920000000030
> var a = parseFloat('135601920000000040');
undefined
> a
135601920000000030
> var n = Number('135601920000000040');
undefined
> n
135601920000000030

Not only node.js, it also happen to js interpreter in Firefox

2
  • have you tried different numbers or only 135601920000000040? if you tried different, what are the results? can you see any pattern that may lead to a solution? Commented Mar 13, 2012 at 10:01
  • Fx too: jsfiddle.net/mplungjan/VqQDH Commented Mar 13, 2012 at 10:03

1 Answer 1

3

The Number type in javascript is represented as double precision floating point, so, it a value passed to parseInt, parseFloat etc is more than 9007199254740992 (ECMAScirpt Numbers specification) it is rouned to fit the Number type.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I got it. javascript don't have a 64bit integer, same as php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.