M
M
maxclax2014-12-17 23:56:52
Django
maxclax, 2014-12-17 23:56:52

Django float output, how right?

In template, all float numbers are displayed separated by a comma :), and not by a dot. Why is that?
How to display a floating point number with a dot?
I also don’t understand how to display a floating point number only, then what is after the point? For example 1234.567 output 567

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
maxclax, 2015-01-04
@maxclax

Found the best solution without various filters and extra code: USE_L10N
Read here djbook.ru/rel1.7/topics/i18n/formatting.html

V
Vladislav, 2014-12-18
@RGV

The filter can be used.
https://docs.djangoproject.com/en/1.7/howto/custom...

from django.template.defaultfilters import floatformat
from django.template import Library

register = Library()


def formatted_float(value):
    value = floatformat(value, arg=4)
    return str(value).replace(',', '.')


register.filter('formatted_float', formatted_float)

A
Alexey, 2014-12-18
@MAKAPOH

This is probably due to internationalization, in Russian the integer and fractional parts are separated by a comma, in English by a dot. Try switching the language.
To manipulate the output, write your own filter if there is no ready one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question