dollarize numbers

1
2
3
4
5
6
@register.filter
def dollarize(c):
    if c>0:
        return "$%s"%c
    else:
        return "-$%s"%(-1*c)

More like this

  1. sublist by nofactor 6 years, 5 months ago
  2. Significant digits filter by joelegner 5 years, 1 month ago
  3. restrict user access to modeladmin via metaclass by code_shogan 3 years, 2 months ago
  4. Humanize lists of strings in templates by ChipX86 6 years, 10 months ago
  5. captcha, verification code by dingdongquan 3 years, 3 months ago

Comments

greencoder (on July 17, 2007):

Unless I did something wrong, it didn't return two decimal places for integers and single point precision numbers. This did the trick:

def dollarize(c):
  if c > 0:
    return "$%.2f" % c
  else:
    return "-$%.2f" % (-1*c)

#

(Forgotten your password?)