0
var i = 20040115102010000;

i++;

returns 20040115102010000;

Do I have to use a Big Number Library?

What is the standard solution in Javascript for handling big numbers (BigNum)?

This number was already in floating point format and I moved the decimal place to the left three times. If your quick you will notice it is a date. Would it behove me to convert this number to a date format first? Will I find it easier to increment in milliseconds in the Date() object?

Community
  • 1
  • 1
TMB
  • 4,663
  • 4
  • 23
  • 44
  • I don't want to sound condescending with the `if you're quick` but I did need to point out that this was really a date. – TMB Mar 10 '13 at 02:43
  • 3
    See http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t. – bfavaretto Mar 10 '13 at 02:44
  • 2
    http://www.thefreedictionary.com/behove – TMB Mar 10 '13 at 02:57

2 Answers2

2

You can't use a Date that big in javascript, without making a bigDay library to handle your bignums.

/*

from 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date':

The JavaScript date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The JavaScript Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC. */

var firstday=new Date(1970,0,1),lastday=new Date(1969,11,31);

firstday.setDate(firstday.getDate()-100000000);

lastday.setDate(lastday.getDate()+100000000);

firstday.toUTCString()+'; timestamp: '+firstday.getTime()+'\n'+
lastday.toUTCString()+'; timestamp: '+lastday.getTime();

/* returned value: (largest and smallest Dates in JS)

Tue, 20 Apr -271821 04:00:00 GMT; timestamp: -8639999985600000

Fri, 12 Sep 275760 04:00:00 GMT; timestamp: 8639999928000000 */

kennebec
  • 98,993
  • 30
  • 103
  • 125
0

JavaScript now has a bigint type.

kzh
  • 18,804
  • 11
  • 69
  • 96