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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -