from django import template

register = template.Library()


@register.filter(name='price_format')
def price_format(value):
    """
    Format a number with thousand separators (commas).
    Example: 1234567 -> 1,234,567
    """
    try:
        # Convert to int to remove decimals
        value = int(float(value))
        # Format with thousand separators
        return "{:,}".format(value)
    except (ValueError, TypeError):
        return value
