From 5c24dfd4083ff70a4133b3566f5280bbe6db959a Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Fri, 5 Mar 2021 20:31:27 +0100 Subject: [PATCH] display decimal digits depending on the amount value fixes #20 --- apps/monitor/templates/monitor.html | 15 ++++++++------- apps/monitor/templatetags/__init__.py | 0 apps/monitor/templatetags/filter.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 apps/monitor/templatetags/__init__.py create mode 100644 apps/monitor/templatetags/filter.py diff --git a/apps/monitor/templates/monitor.html b/apps/monitor/templates/monitor.html index 460123a..e00d961 100644 --- a/apps/monitor/templates/monitor.html +++ b/apps/monitor/templates/monitor.html @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% load filter %} {% block content %}
@@ -16,8 +17,8 @@
@@ -88,7 +89,7 @@ {{ r.dateRelative }} {{ r.date|date:'Y-m-d' }} - {{ r.rateEUR|floatformat:0 }} EUR/{{ c.crypto }} + {{ r.rateEUR|formatcurrency }} EUR/{{ c.crypto }} {% if r.diffPercentage %} {{ r.diffPercentage|floatformat:1 }}% {% endif %} @@ -102,11 +103,11 @@

{{ g.label }}


- Start: {{ g.startdate }} {{ g.startvalue|floatformat:0 }} EUR
- Now: {{ g.curdate }} {{ g.curvalue|floatformat:0 }} EUR
+ Start: {{ g.startdate }} {{ g.startvalue|formatcurrency }} EUR
+ Now: {{ g.curdate }} {{ g.curvalue|formatcurrency }} EUR
Diff: {{ g.diffPercentage|floatformat:1 }} %
- Min: {{ g.mindate }} {{ g.minvalue|floatformat:0 }} EUR
- Max: {{ g.maxdate }} {{ g.maxvalue|floatformat:0 }} EUR
+ Min: {{ g.mindate }} {{ g.minvalue|formatcurrency }} EUR
+ Max: {{ g.maxdate }} {{ g.maxvalue|formatcurrency }} EUR
{% endfor %}
diff --git a/apps/monitor/templatetags/__init__.py b/apps/monitor/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/monitor/templatetags/filter.py b/apps/monitor/templatetags/filter.py new file mode 100644 index 0000000..e556ed3 --- /dev/null +++ b/apps/monitor/templatetags/filter.py @@ -0,0 +1,10 @@ +from django import template + +register = template.Library() + +@register.filter +def formatcurrency(value): + if value > 100: + return "%0.0f" % (value,) + return "%0.2f" % (value,) +