Format numbers in django templates

前端 未结 13 1202
清歌不尽
清歌不尽 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条回答
  •  旧时难觅i
    2020-11-29 18:02

    Not sure why this has not been mentioned, yet:

    {% load l10n %}
    
    {{ value|localize }}
    

    https://docs.djangoproject.com/en/1.11/topics/i18n/formatting/#std:templatefilter-localize

    You can also use this in your Django code (outside templates) by calling localize(number).

提交回复
热议问题