Heavy-tested number formatting function