Fix group formatting and padding.

Very small or large numbers use exponent notation when converted to strings.  If grouping is enabled and there is no decimal, the exponent wasn’t being ignored, so the group separator was in the wrong place.

This also fixes a bug relating to padding and thousands grouping: the padding calculation assumed a grouping of [3].

Fixes #1972, #1994.