Skip to content

Commit

Permalink
floatformat template filter docstring changes:
Browse files Browse the repository at this point in the history
 * Split example cases.
 * Corrected use with negative arguments (quotes are needed).
 * Added another example of a number that has decimal places that include a non-zero digit and that ends with zeros.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
gdub committed Nov 4, 2007
1 parent 75efa28 commit 72b7a33
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions django/template/defaultfilters.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ def fix_ampersands(value):


def floatformat(text, arg=-1): def floatformat(text, arg=-1):
""" """
If called without an argument, displays a floating point Displays a float to a specified number of decimal places.
number as 34.2 -- but only if there's a point to be displayed.
With a positive numeric argument, it displays that many decimal places If called without an argument, it displays the floating point number with
always. one decimal place -- but only if there's a decimal place to be displayed:
With a negative numeric argument, it will display that many decimal
places -- but only if there's places to be displayed.
Examples:
* num1 = 34.23234 * num1 = 34.23234
* num2 = 34.00000 * num2 = 34.00000
* num1|floatformat results in 34.2 * num3 = 34.26000
* num2|floatformat is 34 * {{ num1|floatformat }} displays "34.2"
* num1|floatformat:3 is 34.232 * {{ num2|floatformat }} displays "34"
* num2|floatformat:3 is 34.000 * {{ num3|floatformat }} displays "34.3"
* num1|floatformat:-3 is 34.232
* num2|floatformat:-3 is 34 If arg is positive, it will always display exactly arg number of decimal
places:
* {{ num1|floatformat:3 }} displays "34.232"
* {{ num2|floatformat:3 }} displays "34.000"
* {{ num3|floatformat:3 }} displays "34.260"
If arg is negative, it will display arg number of decimal places -- but
only if there are places to be displayed:
* {{ num1|floatformat:"-3" }} displays "34.232"
* {{ num2|floatformat:"-3" }} displays "34"
* {{ num3|floatformat:"-3" }} displays "34.260"
""" """
try: try:
f = float(text) f = float(text)
Expand Down

0 comments on commit 72b7a33

Please sign in to comment.