Viewing File: /opt/alt/python35/lib/python3.5/site-packages/humanize/__pycache__/number.cpython-35.pyc



ßdTÁã@s
dZddlZddlmZddlmZddlmZm	Z
mZdd„Z
d	d
„Zdd„d*DƒZe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
dƒe
d ƒe
d!ƒe
d"ƒfZd#d$d%„Zd&d'„Zd(d)„ZdS)+z!Humanizing functions for numbers.éN)ÚFractioné)Úcompat)ÚgettextÚgettext_noopÚpgettextcCsåyt|ƒ}Wnttfk
r.|SYnXtddƒtddƒtddƒtddƒtd	dƒtd
dƒtddƒtddƒtd
dƒtddƒf
}|ddkrÏd||dfSd|||dfS)z×Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
    3 is '3rd', etc. Works for any integer or anything int() will turn into an
    integer.  Anything other value will have nothing done to it.Ú0ZthÚ1ÚstÚ2ZndÚ3ZrdÚ4Ú5Ú6Ú7Ú8Ú9édééé
z%d%sré
)rrr)ÚintÚ	TypeErrorÚ
ValueErrorÚP_)ÚvalueÚt©rú
/number.pyÚordinals"	r cCs—y9t|tjƒr.t|jddƒƒn
t|ƒWnttfk
rW|SYnXt|ƒ}tj	dd|ƒ}||kr‰|St
|ƒSdS)zêConverts an integer to a string containing commas every three digits.
    For example, 3000 becomes '3,000' and 45000 becomes '45,000'.  To maintain
    some compatability with Django's intcomma, this function also accepts
    floats.ú,Úz^(-?\d+)(\d{3})z\g<1>,\g<2>N)Ú
isinstancerZstring_typesÚfloatÚreplacerrÚstrÚreÚsubÚintcomma)rZorigÚnewrrrr)"s	r)cCsg|]}d|‘qS)rr)Ú.0Úxrrrú
<listcomp>5s	r-éé	rééééééé!rZmillionZbillionZtrillionZquadrillionZquintillionZ
sextillionZ
septillionZ	octillionZ	nonillionZ	decillionZgoogolz%.1fcCsÆyt|ƒ}Wnttfk
r.|SYnX|tdkrIt|ƒSxpttdd…dƒD]U\}}||krc|tt|dƒ}dj|tt	|dƒgƒ|SqcWt|ƒS)aâConverts a large integer to a friendly text representation. Works best for
    numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
    becomes '1.2 million' and '1200000000' becomes '1.2 billion'.  Supports up to
    decillion (33 digits) and googol (100 digits).  You can pass format to change
    the number of decimal or general format of the number portion.  This function
    returns a string unless the value passed was unable to be coaxed into an int.rrNú )
rrrÚpowersr&Ú	enumerater$ÚjoinÚ_Úhuman_powers)rÚformatr ZpowerZchoppedrrrÚintword;s	
&)r>cCs²yt|ƒ}Wnttfk
r.|SYnXd|koFdknsUt|ƒStdƒtdƒtdƒtdƒtdƒtdƒtd	ƒtd
ƒtdƒf	|dS)
z×For numbers 1-9, returns the number spelled out. Otherwise, returns the
    number. This follows Associated Press style.  This always returns a string
    unless the value was not int-able, unlike the Django filter.rrZoneZtwoZthreeZfourZfiveZsixZsevenZeightZniner)rrrr&r;)rrrrÚapnumberPs	
6r?cCs°yt|ƒ}Wnttfk
r.|SYnXt|ƒ}t||ƒjdƒ}|j}|j}|r‡|r‡|dkr‡d|S|s›d||fSd|||fSdS)as
    There will be some cases where one might not want to show
        ugly decimal places for floats and decimals.
    This function returns a human readable fractional number
        in form of fractions and mixed fractions.
    Pass in a string, or a number or a float, and this function returns
        a string representation of a fraction
        or whole number
        or a mixed fraction
    Examples:
        fractional(0.3) will return '1/3'
        fractional(1.3) will return '1 3/10'
        fractional(float(1/3)) will return '1/3'
        fractional(1) will return '1'
    This will always return a string.
    ièrz%.0fz	%.0f/%.0fz%.0f %.0f/%.0fN)r$rrrrZlimit_denominatorZ
_numeratorZ_denominator)rÚnumberZwholeNumberZfracÚ	numeratorÚdenominatorrrrÚ
fractional^s			rC)r.r/rr0r1r2r3r4r5r6r)Ú__doc__r'Z	fractionsrr"rZi18nrr;rZN_rrr r)r8r<r>r?rCrrrrÚ<module>s$*
Back to Directory File Manager