I'm trying to do some simple math (?) in JavaScript:

```
( 1023 * 2 ) + 76561197960265728;
```

I already did the same calculation in PHP, but the results are different:

JavaScript: **76561197960267780**

PHP: **76561197960267774** (the right result)

I then tried the following: http://jsfiddle.net/YxBa4/

Is there a "limit" in JavaScript for high numbers in calculations?

**//edit:**

Thanks for your answers, I now use the BigNumber one.

My full working code now:

on JSFiddle

asked Mar 24 '23 06:03
#### CREEATION

In Javascript, numbers are 64 bit floating point values. The largest integer (magnitude) is 253, or Math.pow(2,53), or 9007199254740992. taken from: http://notepad2.blogspot.ca/2012/04/maximum-integer-in-javascript.html

You are 1351079458714420 over the limit.

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5. taken from http://php.net/manual/en/language.types.integer.php

So basically PHP allows you more capacity for Integer values according to the PHP configuration.

answered Apr 05 '23 15:04
#### multimediaxp

The value `76561197960265730`

id greater than the maximum allowed number size in javascript. Note that there are no real integers in Javascript just the `Number`

type which is always a 64bit floating point value and platform independent. But the largest possible *integer* value is just 2^53 because 11 bits are at least reserved for the numbers after the comma and the signage bit.

In your example you can see this by simply doing:

```
alert(76561197960265728);
```

What will give you already an error, even without any calculations. (output: '76561197960265730')

In php the maximum integer value depends on your system. If you are on a 64 bit system, the MAX integer value is 2^64 what is greater than (2 * 1023) + 76561197960265728. That'swhy the calculation succeeded in PHP - on a 64 bit system

In PHP you can detect the maximum integer size on your system by reading the constant `PHP_INT_MAX`

and `

answered Apr 05 '23 13:04
#### hek2mgl

### Recent Activity

- Apple Pay - authorize.net returns error 153 only when live, sandbox works
- How to continue cursor loop even error occured in the loop
- python find all neighbours of a given node in a list of lists
- Fatal error: Call to a member function setColumn() on a non-object in Magento
- Count how many of each value from a field with MySQL and PHP
- Python 32-bit development on 64-bit Windows [closed]

If you love us? You can donate to us via Paypal or buy me a coffee
so we can maintain and grow! **Thank you!**