title: Why Sum() in Django returns number with 13 decimal places when evaluating numbers with only 2 decimal places?
body: <p>I am learning Django and creating a cart application.
  What I am trying to do here is to display on the HTML page the sum of all the cart items 'prices'.</p>
  
  <p>Now, I know this is probably the worst way to do it, as I have seen many tutorials, but I'd rather learn step by step.</p>
  
  <p>So what I am doing here is setting the variable 'total' equal to the sum of all prices using the <code>Sum()</code> function documented <a href="https://docs.djangoproject.com/en/2.2/ref/models/querysets/#sum" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The problem is that it displays a number with 13 decimal places, although my model allows just 2 decimal places. How can I overcome this issue?</p>
  
  <p>Here is all the code, and obviously If you have any tip about a better 'basic' way to do this (a best practice) please let me know in the comments.</p>
  
  <p>'models.py'</p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  
  
  # Create your models here.
  class Item(models.Model):
      name = models.CharField(max_length=25)
      price = models.DecimalField(max_digits=5, decimal_places=2)
  
      def __str__(self):
          return self.name
  
  
  class Cart(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      created_at = models.DateTimeField(auto_now_add=True)
      items = models.ManyToManyField(Item)
  
      def __str__(self):
          return 'Order number: %s' % self.id
  </code></pre>
  
  <p>'views.py'</p>
  
  <pre><code>from django.shortcuts import render
  from .models import Cart, Item
  from django.db.models import Sum
  
  
  # Create your views here.
  def home(request):
      items = Item.objects.all()
      carts = Cart.objects.all()
      length = len(Cart.objects.all())
      cart = carts[length - 1]
      cart_items = cart.items.all()
      total = cart_items.aggregate(Sum('price'))['price__sum']
      return render(request, 'cart/home.html', {'cart': cart,
                                                'items': items,
                                                'cart_items': cart_items,
                                                'total': total})
  </code></pre>
  
  <p>and my 'home.html'</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Home page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div&gt;&lt;h1&gt;Menu&lt;/h1&gt;&lt;/div&gt;
  {% for item in items %}
  &lt;ul&gt;{{ item }} £{{ item.price}} &lt;button&gt;Add&lt;/button&gt;&lt;/ul&gt;
  {% endfor %}
  &lt;div&gt;&lt;h1&gt;Order&lt;/h1&gt;&lt;/div&gt;
  {{ cart }}
  {% for item in cart_items %}
      &lt;ul&gt;{{ item.name }} {{ item.price }}&lt;/ul&gt;
  {% endfor %}
  &lt;h2&gt;Total&lt;/h2&gt;
  {{ total }}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>