Format numbers in django templates

前端 未结 13 1163
清歌不尽
清歌不尽 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:09

    Try adding the following line in settings.py:

    USE_THOUSAND_SEPARATOR = True
    

    This should work.

    Refer to documentation.


    update at 2018-04-16:

    There is also a python way to do this thing:

    >>> '{:,}'.format(1000000)
    '1,000,000'
    

提交回复
热议问题