@register.filter(name='cf')
def formattedAmount(amount):
# Convert the numerical amount to a string with comma formatting
formatted_amount = f"{int(amount):,}"
# Determine if the number is positive or negative and set CSS class accordingly
if amount < 0:
css_class = "red-text"
else:
css_class = "green-text"
print(formatted_amount)
# Generate HTML markup with CSS class and formatted amount
return f'<span class="{css_class}">{formatted_amount}</span>'
I am using the custom filter in my HTML code, expecting the output to be:
<span class="green-text">5,492</span>
However, the actual output is different than expected.
Please advise me on how to correct this issue.