# How to subtract one decimal from another.

**URL:** <https://forum.djangoproject.com/t/how-to-subtract-one-decimal-from-another/9237>\
**Category:** Using Django\
**Created:** [August 15, 2021, 12:13pm UTC](https://forum.djangoproject.com/t/how-to-subtract-one-decimal-from-another/9237 "2021-08-15T12:13:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![toppylawz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/toppylawz/32/3044_2.png) [@toppylawz](https://forum.djangoproject.com/u/toppylawz)\
**Post date:** [August 15, 2021, 12:13pm UTC](https://forum.djangoproject.com/t/how-to-subtract-one-decimal-from-another/9237/1 "2021-08-15T12:13:14Z")

</div>

I have a model with the following:

```auto
regular_price = models.DecimalField(

        verbose_name=("Regular price"),

        help_text=("Price you which to sell the product"),

        error_messages={

            "name": {

                "max_length": ("The price you want to sell the product"),

            },

        },

        max_digits=10,

        decimal_places=2, default=0

    )

    discount_price = models.DecimalField(

        verbose_name=("Discount price"),

        help_text=(

            "The amount you want to remove from the actual price, leave to reduce nothing"),

        error_messages={

            "name": {

                "max_length": ("you can leave or put the price you want to reduce."),

            },

        },

        max_digits=10,

        decimal_places=2, blank=True, null=True

```

Now I have a function that calculates the actual price:

```auto
    def actual_price(self):
        price = (self.regular_price)-(self.discount_price)
        return price

```

when I call the function (actual\_price) from the front end, I keep receiving the following error message:

### unsupported operand type(s) for -: ‘decimal.Decimal’ and ‘NoneType’

My question is that what is the proper way to perform subtraction of decimals in django?

---

<div class="post-metadata">

**Author:** ![toppylawz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/toppylawz/32/3044_2.png) [@toppylawz](https://forum.djangoproject.com/u/toppylawz)\
**Post date:** [August 15, 2021, 12:43pm UTC](https://forum.djangoproject.com/t/how-to-subtract-one-decimal-from-another/9237/2 "2021-08-15T12:43:55Z")

</div>

I have gotten the reason for the error, I simply need to give a default value of 0 to the discount\_price, this will make it possible for any mathematical calculation to occur.
