summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Wilson Jr <gary.wilson@gmail.com>2007-11-04 02:27:17 +0000
committerGary Wilson Jr <gary.wilson@gmail.com>2007-11-04 02:27:17 +0000
commit72b7a33929dd6f61ad8d62152ac800d5501778da (patch)
tree502ad4d1fe7b10fc4c716751c45c98278387dd9d
parent75efa2811d5d1300095301cd5b3fdbbce4ae4fdc (diff)
`floatformat` template filter docstring changes:
* 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
-rw-r--r--django/template/defaultfilters.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 0a7a5afc9d..d2d4b9e508 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -54,22 +54,31 @@ fix_ampersands = stringfilter(fix_ampersands)
def floatformat(text, arg=-1):
"""
- If called without an argument, displays a floating point
- 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
- always.
- With a negative numeric argument, it will display that many decimal
- places -- but only if there's places to be displayed.
- Examples:
+ Displays a float to a specified number of decimal places.
+
+ If called without an argument, it displays the floating point number with
+ one decimal place -- but only if there's a decimal place to be displayed:
* num1 = 34.23234
* num2 = 34.00000
- * num1|floatformat results in 34.2
- * num2|floatformat is 34
- * num1|floatformat:3 is 34.232
- * num2|floatformat:3 is 34.000
- * num1|floatformat:-3 is 34.232
- * num2|floatformat:-3 is 34
+ * num3 = 34.26000
+ * {{ num1|floatformat }} displays "34.2"
+ * {{ num2|floatformat }} displays "34"
+ * {{ num3|floatformat }} displays "34.3"
+
+ 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:
f = float(text)