Question: I'm developing a 3D space game, which is using alot of math formulas, navigation, ease effects, rotations, huge distances between planets, objects mass, and so on...

My Question is what would be the best way in doing so using math. Should I calculate everything as integers and obtain really large integers(over 20 digits), or use small numbers with decimals.

In my experience, math when using digits with decimals is not accurate, causing strange behavior when using large numbers with decimals.

Answer: 
I would avoid using decimals. They have known issues with precision: <http://floating-point-gui.de/>

---

I would recommend using integers, though if you need to work with very large integers I would suggest using a big number or big integer library such as one of these:

* <http://jsfromhell.com/classes/bignumber>
* <https://silentmatt.com/biginteger/>

The downside is you have to use these number objects and their methods rather than the primitive Number type and standard JS operators, but you'll have a lot more flexibility with operating on large numbers.

**Edit:**

As [le\_m](https://stackoverflow.com/users/1647737/le-m "le_m") pointed out, another downside is speed. The library methods won't run as fast as the native operators. You'll have to test for yourself to see if the performance is acceptable.
The problem with [BigNumber](https://github.com/MikeMcl/bignumber.js/) is with 

> 
> Precision loss from using numeric literals with more than 15
>  significant digits
> 
> 
> 

My solution would be a combination of BigNumber and [web3.js](https://github.com/ethereum/wiki/wiki/JavaScript-API#web3towei*):

```
var web3 = new Web3();
let one = new BigNumber("1234567890121234567890123456789012345");
let two =   new BigNumber("1000000000000000000");
let three = new BigNumber("1000000000000000000");
const minus = two.times(three).minus(one);
const plus = one.plus(two.times(three));
const compare = minus.comparedTo(plus);
const results = {
    minus: web3.toBigNumber(minus).toString(10),
    plus: web3.toBigNumber(plus).toString(10),
    compare
}
console.log(results); // {minus: "-234567890121234567890123456789012345", plus: "2234567890121234567890123456789012345", compare: -1}

```