.toNumber returns NaN for some large numbers.

This PR addresses the issue, but not the root cause.
Needs testing to verify that calculation is still correct.