From 47809d83d4676243a482b4f4a5e33c880ee56f27 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Fri, 27 Sep 2024 16:28:28 -0300 Subject: [PATCH] feat: properly displays the negative signal before prefix --- app/apps/transactions/templatetags/currency_display.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/apps/transactions/templatetags/currency_display.py b/app/apps/transactions/templatetags/currency_display.py index cd34d3b..3d4d507 100644 --- a/app/apps/transactions/templatetags/currency_display.py +++ b/app/apps/transactions/templatetags/currency_display.py @@ -1,4 +1,3 @@ -import datetime from django import template from django.template.defaultfilters import floatformat @@ -8,7 +7,11 @@ register = template.Library() def _format_string(prefix, amount, decimal_places, suffix): - return f"{prefix}{floatformat(amount, decimal_places)}{suffix}" + formatted_amount = floatformat(abs(amount), f"{decimal_places}g") + if amount < 0: + return f"-{prefix}{formatted_amount}{suffix}" + else: + return f"{prefix}{formatted_amount}{suffix}" @register.simple_tag(name="transaction_amount")