Skip to content

A small reusable Django application for which provides filters for Django templates for formatting numbers in Indian Number System.

License

Notifications You must be signed in to change notification settings

narenchoudhary/django-indian-numbers

Repository files navigation

django-indian-numbers

https://app.travis-ci.com/narenchoudhary/django-indian-numbers.svg?branch=master

django-indian-numbers is a reusable Django application for which provides filters for Django templates for formatting numbers in Indian Number System .

Installation

pip install git+https://github.com/narenchoudhary/django-indian-numbers#egg=django-indian-numbers

Usage

  1. Add "indian_numbers" to INSTALLED_APPS settings.
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    ...
    'indian_numbers',
]
  1. Add USE_THOUSAND_SEPARATOR = True in settings.
  2. Load the indian_numbers_tags template filters library.
{% load indian_numbers_tags %}
  1. See example project for examples.

Filters

intcomma_indian

Similar to intcomma in django.contrib.humanize app of Django library. It converts a number to a string formatted with commas as per Indian number system. It works for integer, floating-point and string values which can be converted to integers. This tag also accepts an optional preserve_decimal parameter. If preserve_decimal is True, then tag will preserve the decimal places for the provided number. By default, preserve_decimal is set to False.

Examples:

  • 100000 becomes 1,00,000
  • 1259647552 becomes 1,25,96,47,552
  • 126500.25 becomes 1,26,500
  • -126500 becomes -1,26,500
  • 100000 becomes 1,00,000

floatcomma_indian

It works exactly likes intcomma, except that it preserves decimal places. This template tag also accepts an optional decimal_pos parameter which denotes number of decimal positions to add/preserve in the provided floating point number. By default, all decimal places are preserved (no decimal places are truncated/padded).

Examples:

  • 25 becomes 25.00
  • 121250.6 becomes 1,125.6
  • 25.675 becomes 25.675
  • 126500.25 becomes 1,26,500.25
  • 126500.75 becomes -1,26,500.75

floatword_indian

Converts a large integer number into a friendly text representation. Highest Denomination is used and 2 lower powers are considered for floating points in text representation. Numbers less than 99 are returned without conversion.

Denominations used are: Hundred, Thousand, Lakh, Crore

Examples:

  • 1000 becomes 1 Thousand
  • 15000 becomes 15 Thousands
  • 15600 becomes 15.60 Thousands
  • 100000 becomes 1 Lakh
  • 1125000 becomes 11.25 Lakhs
  • 10000000 becomes 1 Crore
  • 56482485 becomes 5.64 Crore
  • 56482485.25 becomes 5.64 Crores

About

A small reusable Django application for which provides filters for Django templates for formatting numbers in Indian Number System.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published