mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-23 17:18:44 +02:00
feat: display error when amount can't be displayed
This commit is contained in:
@@ -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