BUG: Fix rollover handling in json encoding
This is a fix attempt for issue #15716 as well as #15864.

Note that whenever the frac is incremented, there is a chance that its
value may hit the value of pow10.