improve conditional expression in number formatting
specify exception as TypeError