Javascript stores numbers as double-precision (64-bit) floats. Integer precision only goes as far as 2^53, or about 9x10^15. Beyond that there is not enough precision to reliably increment the number by 1. The precision goes lower the higher you go, and so math operations become more imprecise.
The easiest solution is probably just fake it. Store numbers in units of say billions, so 9 trillion is actually stored as 9000. Then when you display it to the user, use a string and just append the characters "000000000". The user sees 9 trillion, but you only stored 9000.