mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-18 14:48:42 +01:00
feat: display error when amount can't be displayed
This commit is contained in:
1 parent
d5e207fc9c
commit
436984eaac
1 file changed
+11
-6
@@ -1,3 +1,5 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django import template
|
||||
from django.utils.formats import number_format
|
||||
|
||||
@@ -6,13 +8,16 @@ register = template.Library()
|
||||
|
||||
|
||||
def _format_string(prefix, amount, decimal_places, suffix):
|
||||
formatted_amount = number_format(
|
||||
value=abs(amount), decimal_pos=decimal_places, force_grouping=True
|
||||
)
|
||||
if amount < 0:
|
||||
return f"-{prefix}{formatted_amount}{suffix}"
|
||||
if isinstance(amount, (int, float, Decimal)):
|
||||
formatted_amount = number_format(
|
||||
value=abs(amount), decimal_pos=decimal_places, force_grouping=True
|
||||
)
|
||||
if amount < 0:
|
||||
return f"-{prefix}{formatted_amount}{suffix}"
|
||||
else:
|
||||
return f"{prefix}{formatted_amount}{suffix}"
|
||||
else:
|
||||
return f"{prefix}{formatted_amount}{suffix}"
|
||||
return "ERR"
|
||||
|
||||
|
||||
@register.simple_tag(name="currency_display")
|
||||
|
||||
Reference in new issue
Block a user