Skip to content Skip to sidebar Skip to footer

Python Format Negative Currency

I haven't found anything that addresses how to format negative currency, so far, and it is driving me crazy. from decimal import * import re import sys import os import locale lo

Solution 1:

Looks like you can use the _override_localeconv dict (which is a 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 you could use string formatting.

Post a Comment for "Python Format Negative Currency"