Format numbers in django templates

前端 未结 13 1166
清歌不尽
清歌不尽 2020-11-29 17:22

I\'m trying to format numbers. Examples:

1     => 1
12    => 12
123   => 123
1234  => 1,234
12345 => 12,345

It strikes as a

13条回答
  •  既然无缘
    2020-11-29 18:07

    Well I couldn't find a Django way, but I did find a python way from inside my model:

    def format_price(self):
        import locale
        locale.setlocale(locale.LC_ALL, '')
        return locale.format('%d', self.price, True)
    

提交回复
热议问题