strip trailing zeros only from fractional part, not from exponent

Trailing (significant) zeros were being stripped from the exponent when using %g. This patch fixes the problem.