formatting - Python format negative currency -
i haven't found addresses how format negative currency, far, , driving me crazy.
from decimal import * import re import sys import os import locale locale.setlocale( locale.lc_all, 'english_united states.1252' ) # cbalance running balance of type decimal fbalance = locale.currency( cbalance, grouping=true ) print cbalance, fbalance
result negative number:
-496.06 ($496.06)
i need minus sign not parenthesis
how rid of parenthesis , minus signs?
looks can use _override_localeconv
dict (which bit hackish).
import locale cbalance = -496.06 locale.setlocale( locale.lc_all, 'english_united states.1252') locale._override_localeconv = {'n_sign_posn':1} fbalance = locale.currency(cbalance, grouping=true) print cbalance, fbalance
or use string formatting.
Comments
Post a Comment