[Python] Babel numbers format_currency function

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a site where we use many languages and in order to display the price/currency accordingly we make use of babel library. The issue is when calling the format_currency it returns always the cent part if even if the price is explicitly casted into an integer.

    Example:

    >>> print format_currency(100, 'EUR', locale='fr_FR')
    100,00 €

    >>> print format_currency(int(100), 'EUR', locale='fr_FR')
    100,00 €


    Is it a way around this so that the return value excludes the cent part to have something like

    >>> print format_currency(int(100), 'EUR', locale='fr_FR')
    100 €

    Continue reading...

Compartilhe esta Página