How to use the num2words.base.Num2Word_Base function in num2words

To help you get started, we’ve selected a few num2words examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github savoirfairelinux / num2words / tests / test_base.py View on Github external
def setUpClass(cls):
        super(Num2WordBaseTest, cls).setUpClass()
        cls.base = Num2Word_Base()
github savoirfairelinux / num2words / num2words / lang_KZ.py View on Github external
THOUSANDS = {
    1: 'мың',
    2: 'миллион',
    3: 'миллиард',
    4: 'триллион',
    5: 'квадриллион',
    6: 'квинтиллион',
    7: 'секстиллион',
    8: 'септиллион',
    9: 'октиллион',
    10: 'нониллион',
}


class Num2Word_KZ(Num2Word_Base):
    CURRENCY_FORMS = {
        'USD': ('доллар', 'цент'),
        'KZT': ('теңге', 'тиын'),
    }

    def setup(self):
        self.negword = "минус"
        self.pointword = "бүтін"

    def to_cardinal(self, number):
        n = str(number).replace(',', '.')
        if '.' in n:
            left, right = n.split('.')
            return u'%s %s %s' % (
                self._int2word(int(left)),
                self.pointword,
github savoirfairelinux / num2words / num2words / lang_LT.py View on Github external
1: ('tūkstantis', 'tūkstančiai', 'tūkstančių'),
    2: ('milijonas', 'milijonai', 'milijonų'),
    3: ('milijardas', 'milijardai', 'milijardų'),
    4: ('trilijonas', 'trilijonai', 'trilijonų'),
    5: ('kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'),
    6: ('kvintilijonas', 'kvintilijonai', 'kvintilijonų'),
    7: ('sikstilijonas', 'sikstilijonai', 'sikstilijonų'),
    8: ('septilijonas', 'septilijonai', 'septilijonų'),
    9: ('oktilijonas', 'oktilijonai', 'oktilijonų'),
    10: ('naintilijonas', 'naintilijonai', 'naintilijonų'),
}

GENERIC_CENTS = ('centas', 'centai', 'centų')


class Num2Word_LT(Num2Word_Base):
    CURRENCY_FORMS = {
        'LTL': (('litas', 'litai', 'litų'), GENERIC_CENTS),
        'EUR': (('euras', 'eurai', 'eurų'), GENERIC_CENTS),
        'USD': (('doleris', 'doleriai', 'dolerių'), GENERIC_CENTS),
        'GBP': (
            ('svaras sterlingų', 'svarai sterlingų', 'svarų sterlingų'),
            ('pensas', 'pensai', 'pensų')
        ),
        'PLN': (
            ('zlotas', 'zlotai', 'zlotų'),
            ('grašis', 'grašiai', 'grašių')),
        'RUB': (
            ('rublis', 'rubliai', 'rublių'),
            ('kapeika', 'kapeikos', 'kapeikų')
        ),
    }
github savoirfairelinux / num2words / num2words / lang_EU.py View on Github external
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import unicode_literals

from .base import Num2Word_Base

GENERIC_DOLLARS = ('dollar', 'dollars')
GENERIC_CENTS = ('cent', 'cents')


class Num2Word_EU(Num2Word_Base):
    CURRENCY_FORMS = {
        'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
        'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
        # repalced by EUR
        'EEK': (('kroon', 'kroons'), ('sent', 'senti')),
        'EUR': (('euro', 'euro'), GENERIC_CENTS),
        'GBP': (('pound sterling', 'pounds sterling'), ('penny', 'pence')),
        # replaced by EUR
        'LTL': (('litas', 'litas'), GENERIC_CENTS),
        # replaced by EUR
        'LVL': (('lat', 'lats'), ('santim', 'santims')),
        'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
        'RUB': (('rouble', 'roubles'), ('kopek', 'kopeks')),
        'SEK': (('krona', 'kronor'), ('öre', 'öre')),
        'NOK': (('krone', 'kroner'), ('øre', 'øre')),
        'PLN': (('zloty', 'zlotys', 'zlotu'), ('grosz', 'groszy')),
github savoirfairelinux / num2words / num2words / lang_JA.py View on Github external
(1831, ("天保", "てんぽう")),
    (1845, ("弘化", "こうか")),
    (1848, ("嘉永", "かえい")),
    (1855, ("安政", "あんせい")),
    (1860, ("万延", "まんえい")),
    (1861, ("文久", "ぶんきゅう")),
    (1864, ("元治", "げんじ")),
    (1865, ("慶応", "けいおう")),
    (1868, ("明治", "めいじ")),
    (1912, ("大正", "たいしょう")),
    (1926, ("昭和", "しょうわ")),
    (1989, ("平成", "へいせい")),
]


class Num2Word_JA(Num2Word_Base):
    CURRENCY_FORMS = {
        'JPY': (('円', 'えん'), ()),
    }

    def set_high_numwords(self, high):
        max = 4 * len(high)
        for word, n in zip(high, range(max, 0, -4)):
            self.cards[10 ** n] = word

    def setup(self):
        self.negword = "マイナス"
        self.pointword = ("点", "てん")
        self.exclude_title = ["点", "マイナス"]

        self.high_numwords = [
            ("万", "まん"),    # 10**4 man
github savoirfairelinux / num2words / num2words / lang_CZ.py View on Github external
THOUSANDS = {
    1: ('tisíc', 'tisíce', 'tisíc'),  # 10^3
    2: ('milion', 'miliony', 'milionů'),  # 10^6
    3: ('miliarda', 'miliardy', 'miliard'),  # 10^9
    4: ('bilion', 'biliony', 'bilionů'),  # 10^12
    5: ('biliarda', 'biliardy', 'biliard'),  # 10^15
    6: ('trilion', 'triliony', 'trilionů'),  # 10^18
    7: ('triliarda', 'triliardy', 'triliard'),  # 10^21
    8: ('kvadrilion', 'kvadriliony', 'kvadrilionů'),  # 10^24
    9: ('kvadriliarda', 'kvadriliardy', 'kvadriliard'),  # 10^27
    10: ('quintillion', 'quintilliony', 'quintillionů'),  # 10^30
}


class Num2Word_CZ(Num2Word_Base):
    CURRENCY_FORMS = {
        'CZK': (
            ('koruna', 'koruny', 'korun'), ('halíř', 'halíře', 'haléřů')
        ),
        'EUR': (
            ('euro', 'euro', 'euro'), ('cent', 'centy', 'centů')
        ),
    }

    def setup(self):
        self.negword = "mínus"
        self.pointword = "celá"

    def to_cardinal(self, number):
        n = str(number).replace(',', '.')
        if '.' in n:
github savoirfairelinux / num2words / num2words / lang_SR.py View on Github external
SCALE = {
    0: ('', '', '', False),
    1: ('hiljada', 'hiljade', 'hiljada', True),  # 10^3
    2: ('milion', 'miliona', 'miliona', False),  # 10^6
    3: ('bilion', 'biliona', 'biliona', False),  # 10^9
    4: ('trilion', 'triliona', 'triliona', False),  # 10^12
    5: ('kvadrilion', 'kvadriliona', 'kvadriliona', False),  # 10^15
    6: ('kvintilion', 'kvintiliona', 'kvintiliona', False),  # 10^18
    7: ('sekstilion', 'sekstiliona', 'sekstiliona', False),  # 10^21
    8: ('septilion', 'septiliona', 'septiliona', False),  # 10^24
    9: ('oktilion', 'oktiliona', 'oktiliona', False),  # 10^27
    10: ('nonilion', 'noniliona', 'noniliona', False),  # 10^30
}


class Num2Word_SR(Num2Word_Base):
    CURRENCY_FORMS = {
        'RUB': (
            ('rublja', 'rublje', 'rublji', True),
            ('kopejka', 'kopejke', 'kopejki', True)
        ),
        'EUR': (
            ('evro', 'evra', 'evra', False),
            ('cent', 'centa', 'centi', False)
        ),
        'RSD': (
            ('dinar', 'dinara', 'dinara', False),
            ('para', 'pare', 'para', True)
        ),
    }

    def setup(self):
github savoirfairelinux / num2words / num2words / lang_LV.py View on Github external
5: ('kvadriljons', 'kvadriljoni', 'kvadriljonu'),
    6: ('kvintiljons', 'kvintiljoni', 'kvintiljonu'),
    7: ('sikstiljons', 'sikstiljoni', 'sikstiljonu'),
    8: ('septiljons', 'septiljoni', 'septiljonu'),
    9: ('oktiljons', 'oktiljoni', 'oktiljonu'),
    10: ('nontiljons', 'nontiljoni', 'nontiljonu'),
}

GENERIC_DOLLARS = ('dolārs', 'dolāri', 'dolāru')
GENERIC_CENTS = ('cents', 'centi', 'centu')

GENERIC_KRONA = ('krona', 'kronas', 'kronu')
GENERIC_ERA = ('ēre', 'ēras', 'ēru')


class Num2Word_LV(Num2Word_Base):
    """
    Sadly we have a legal form (used in legal and finance documents):
    http://www.eiro.lv/files/upload/files/Eiro_rakstiba-1.pdf
    https://likumi.lv/doc.php?id=254741
    http://eur-lex.europa.eu/legal-content/LV/TXT/HTML/?uri=CELEX:31998R0974&from=LV

    Source: http://publications.europa.eu/code/lv/lv-5000500.htm
    """
    CURRENCY_FORMS = {
        'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
        'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
        # repalced by EUR
        'EEK': (GENERIC_KRONA, GENERIC_CENTS),
        'EUR': (('eiro', 'eiro', 'eiro'), GENERIC_CENTS),
        'EUR_LEGAL': (('euro', 'euro', 'euro'), GENERIC_CENTS),
        'GBP': (
github savoirfairelinux / num2words / num2words / lang_UK.py View on Github external
THOUSANDS = {
    1: ('тисяча', 'тисячi', 'тисяч'),  # 10^3
    2: ('мiльйон', 'мiльйони', 'мiльйонiв'),  # 10^6
    3: ('мiльярд', 'мiльярди', 'мiльярдiв'),  # 10^9
    4: ('трильйон', 'трильйони', 'трильйонiв'),  # 10^12
    5: ('квадрильйон', 'квадрильйони', 'квадрильйонiв'),  # 10^15
    6: ('квiнтильйон', 'квiнтильйони', 'квiнтильйонiв'),  # 10^18
    7: ('секстильйон', 'секстильйони', 'секстильйонiв'),  # 10^21
    8: ('септильйон', 'септильйони', 'септильйонiв'),  # 10^24
    9: ('октильйон', 'октильйони', 'октильйонiв'),  # 10^27
    10: ('нонiльйон', 'нонiльйони', 'нонiльйонiв'),  # 10^30
}


class Num2Word_UK(Num2Word_Base):
    CURRENCY_FORMS = {
        'UAH': (
            ('гривня', 'гривнi', 'гривень'),
            ('копiйка', 'копiйки', 'копiйок')
        ),
        'EUR': (
            ('євро', 'євро', 'євро'), ('цент', 'центи', 'центiв')
        ),
    }

    def setup(self):
        self.negword = "мiнус"
        self.pointword = "кома"

    def to_cardinal(self, number):
        n = str(number).replace(',', '.')
github savoirfairelinux / num2words / num2words / lang_KO.py View on Github external
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import division, print_function, unicode_literals

from .base import Num2Word_Base
from .currency import parse_currency_parts


class Num2Word_KO(Num2Word_Base):
    CURRENCY_FORMS = {
        'KRW': ('원', None),
        'USD': ('달러', '센트'),
        'JPY': ('엔', None)
    }

    def set_high_numwords(self, high):
        max = 4 * len(high)
        for word, n in zip(high, range(max, 0, -4)):
            self.cards[10 ** n] = word

    def setup(self):
        super(Num2Word_KO, self).setup()

        self.negword = "마이너스 "
        self.pointword = "점"