chg: generalize number formatting function
and make it work with negative numbers