Ticket #6151: fixed-formatfloat-formatting.diff

File fixed-formatfloat-formatting.diff, 2.8 KB (added by Adam Vandenberg, 16 years ago)
  • docs/templates.txt

     
    13351335When used without an argument, rounds a floating-point number to one decimal
    13361336place -- but only if there's a decimal part to be displayed. For example:
    13371337
    1338 ========  =======================  ======
    1339 value     Template                 Output
    1340 ========  =======================  ======
    1341 34.23234  {{ value|floatformat }}  34.2
    1342 34.00000  {{ value|floatformat }}  34
    1343 34.26000  {{ value|floatformat }}  34.3
    1344 ========  =======================  ======
     1338============  ===========================  ========
     1339Value         Template                     Output
     1340============  ===========================  ========
     1341``34.23234``  ``{{ value|floatformat }}``  ``34.2``
     1342``34.00000``  ``{{ value|floatformat }}``  ``34``
     1343``34.26000``  ``{{ value|floatformat }}``  ``34.3``
     1344============  ===========================  ========
    13451345
    13461346If used with a numeric integer argument, ``floatformat`` rounds a number to
    13471347that many decimal places. For example:
    13481348
    1349 ========  =========================  ======
    1350 value     Template                   Output
    1351 ========  =========================  ======
    1352 34.23234  {{ value|floatformat:3 }}  34.232
    1353 34.00000  {{ value|floatformat:3 }}  34.000
    1354 34.26000  {{ value|floatformat:3 }}  34.260
    1355 ========  =========================  ======
     1349============  =============================  ==========
     1350Value         Template                       Output
     1351============  =============================  ==========
     1352``34.23234``  ``{{ value|floatformat:3 }}``  ``34.232``
     1353``34.00000``  ``{{ value|floatformat:3 }}``  ``34.000``
     1354``34.26000``  ``{{ value|floatformat:3 }}``  ``34.260``
     1355============  =============================  ==========
    13561356
    13571357If the argument passed to ``floatformat`` is negative, it will round a number
    13581358to that many decimal places -- but only if there's a decimal part to be
    13591359displayed. For example:
    13601360
    1361 ========  ============================  ======
    1362 value     Template                      Output
    1363 ========  ============================  ======
    1364 34.23234  {{ value|floatformat:"-3" }}  34.232
    1365 34.00000  {{ value|floatformat:"-3" }}  34
    1366 34.26000  {{ value|floatformat:"-3" }}  34.260
    1367 ========  ============================  ======
     1361============  ================================  ==========
     1362Value         Template                          Output
     1363============  ================================  ==========
     1364``34.23234``  ``{{ value|floatformat:"-3" }}``  ``34.232``
     1365``34.00000``  ``{{ value|floatformat:"-3" }}``  ``34``
     1366``34.26000``  ``{{ value|floatformat:"-3" }}``  ``34.260``
     1367============  ================================  ==========
    13681368
    13691369Using ``floatformat`` with no argument is equivalent to using ``floatformat``
    13701370with an argument of ``-1``.
Back to Top