3
W­E^  ã               @   s2   d dl mZ d dlmZ d dlmZ d	dd„ZdS )
é    )ÚDecimal)Úsettings)Ú	mark_safeNÚ Fc             C   s>  |s|dkot jot j}|p|}|o*|dk}t| tƒrJ| rJ| rJt| ƒS d}t| tƒrî|dk	rˆtddj|dƒ ƒ}	t| ƒ|	k rˆtdƒ} | j	ƒ \}
}}t|ƒt
|ƒ dkrâdj| ƒ} | jd	ƒ\}}t|||||||ƒ}d
j||ƒS dj| ƒ}nt| ƒ}|d dk�rd}|dd… }d|k�rD|jdƒ\}}|dk	�rN|d|… }n
|d }}|dk	�rl|d|t
|ƒ   }|�ox|| }|�r2yt|ƒ}W n tk
�rª   |dg}Y nX |jdƒ}d}d}xd|ddd… D ]R}|�r||k�r|�rø|jdƒ�pö|}||ddd… 7 }d}||7 }|d7 }�qÎW |ddd… }|| | S )aT  
    Get a number (as a number or string), and return it as a string,
    using formats defined as arguments:

    * decimal_sep: Decimal separator symbol (for example ".")
    * decimal_pos: Number of decimal positions
    * grouping: Number of digits in every group limited by thousand separator.
        For non-uniform digit grouping, it can be a sequence with the number
        of digit group sizes following the format used by the Python locale
        module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)).
    * thousand_sep: Thousand separator symbol (for example ",")
    Nr   r   z0.Ú1Ú0éÈ   z{:e}Úez{}e{}z{:f}ú-é   Ú.éÿÿÿÿr   r   )r   ZUSE_L10NZUSE_THOUSAND_SEPARATORÚ
isinstanceÚintr   r   ÚrjustÚabsÚas_tupleÚlenÚformatÚsplitÚstrÚlistÚ	TypeErrorÚpop)ÚnumberZdecimal_sepZdecimal_posÚgroupingZthousand_sepZforce_groupingZuse_l10nZuse_groupingÚsignÚcutoffÚ_ÚdigitsÚexponentZcoefficientZ
str_numberZint_partZdec_partZ	intervalsZactive_intervalZint_part_gdZcntÚdigit© r"   ú;/tmp/pip-build-78s3knkw/Django/django/utils/numberformat.pyr      sd    







r   )Nr   r   FN)Údecimalr   Zdjango.confr   Zdjango.utils.safestringr   r   r"   r"   r"   r#   Ú<module>   s    