对python这个高级语言感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
python开发中时长到货币格式化的问题,一般情况下可以使用locale模块。但是这个模块使用起来不是那么顺手,今天我为大家介绍一个很好用的方法。
直接上代码。。。
from decimal import *
def moneyfmt(value,places=2,curr='',sep=',',dp='.',pos='',neg='-',trailneg=''):
"""Convert Decimal to a money formatted string.
places: required number of places after the decimal point
curr: optional currency symbol before the sign (may be blank)
sep: optional grouping separator (comma,period,space,or blank)
dp: decimal point indicator (comma or period)
only specify as blank when places is zero
pos: optional sign for positive numbers: '+',space or blank
neg: optional sign for negative numbers: '-','(',space or blank
trailneg:optional trailin