# A story that I wanted to display the division result (%) on HTML with an application using django [Beginner learns python with a reference book in one hand]

## Introduction

Using Takashi Otaka, "Learning by Moving! Introduction to Python Django Development" I'm a beginner who started learning python and Django.

I've been studying programming for about 4 months using ruby / rails, When I changed jobs as an engineer, I decided to use python, so I started studying with this book in my hand.

Since I am a de-class amateur, I would be very grateful if you could comment on supplements and suggestions.

## Overview

I want to display the division result (percentage) on the HTML of the app created by django. I also want you to round it off.

## What I tried

I decided to make my own filter. Below is a quote from the __old __ver. Documentation. https://djangoproject.jp/doc/ja/1.0/howto/custom-template-tags.html

### ① Create the templatetags directory and the following files

Have a directory file that describes your custom templates and filters. Keep the hierarchy in the same hierarchy as models.py and views.py.

``````views.py
models.py
.
.
.
templatetags
├─　__init__.py
└─　hoge_tag.py
``````

### ② Describe the division process in hoge_tag.py

Round with the round function. value → number to be divided args → number to divide Name the filter division.

#### `hoge_tag.py`

``````
from django import template

register = template.Library()

@register.filter(name="division")
def division(value, args):
return round(value / args * 100, 2)
``````

The last "2" defines how many decimal places to leave after rounding. __ * However, you need to be careful about how to round numbers using the round function. __

The behavior of round () on floating point numbers may be surprising: for example, round (2.675, 2) gives 2.67 instead of 2.68 as expected. This is not a bug: This is the result of most decimals not being accurately represented by floating point numbers.

For details, refer to the following. https://docs.python.org/ja/3/library/functions.html#round

### ③ Read hoge_tag.py in HTML

Add the following so that the calculation formula can be read in the HTML that you want to use the above calculation formula.

#### `fuga.html`

``````
#### `fuga.html`
``````