Fix for #14317 (number formatting issues)

Fix based off the diff in https://code.djangoproject.com/ticket/14317
Please review @akaariai.