I'm working on a Django APP that has LANGUAGE_CODE
set to es
for Spanish.
I'm trying to format how the numbers are rendered in the templates. Right now they're rendered like:S/ 18,00
when S/ 18.00
is needed.
I've search and found this other related question:
Format numbers in django templates
But after applying Humanize, I'm not getting the desired result:
template.html:
{% load humanize %}
<p>El total de su pedido es: S/ {{ total|intcomma }}</p> #renders S/ 18,00
settings.py:
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'shop',
'django.contrib.humanize',
]
I've also tried these other solutions:
1) <p>El total de su pedido es: S/ {{ total|floatformat:'2' }}</p>
Doesn't work, renders: S/ 18,00
when S/ 18.00
is needed.
2) <p>El total de su pedido es: S/ {{ total|stringformat:"f" }}</p>
Works but uses more than 2 decimals: S/ 18.00000000
when S/ 18.00
is needed.
3) <p>El total de su pedido es: S/ {{ total|stringformat:"2f" }}</p>
This does not work, also returns: S/ 18.00000000
when S/ 18.00
is needed.
models.py:
class Order(models.Model):
token = models.CharField(max_length=100, blank=True, null=True)
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)
total = models.DecimalField(max_digits=10, decimal_places=2)
views.py
def thanks_deposit_payment(request):
order_number = Order.objects.latest('id').id
total = Order.objects.latest('id').total
response = render(request, 'thanks_deposit_payment.html', dict(order_number=order_number, total=total))
return response
Other language settings that may help:
LANGUAGE_CODE = 'es'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True