How to use the num2words.utils.splitbyx 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_utils.py View on Github external
def test_splitbyx(self):
        self.assertEqual(list(splitbyx(str(12), 3)), [12])
        self.assertEqual(list(splitbyx(str(1234), 3)), [1, 234])
        self.assertEqual(list(splitbyx(str(12345678900), 3)),
                         [12, 345, 678, 900]
                         )
        self.assertEqual(list(splitbyx(str(1000000), 6)), [1, 0])

        self.assertEqual(list(splitbyx(str(12), 3, format_int=False)), ['12'])
        self.assertEqual(list(splitbyx(str(1234), 3, format_int=False)),
                         ['1', '234']
                         )
        self.assertEqual(list(splitbyx(str(12345678900), 3, format_int=False)),
                         ['12', '345', '678', '900']
                         )
        self.assertEqual(list(splitbyx(str(1000000), 6, format_int=False)),
                         ['1', '000000']
                         )
github savoirfairelinux / num2words / num2words / lang_TH.py View on Github external
def split_six(self, num_txt):
        result = splitbyx(num_txt, 6, format_int=False)
        result = list(result)[::-1]
        number_list = []
        for i in result:
            number_list.append(i[::-1])
        return number_list
github savoirfairelinux / num2words / num2words / lang_LT.py View on Github external
def _int2word(self, n, feminine=False):
        if n == 0:
            return ZERO[0]

        words = []
        chunks = list(splitbyx(str(n), 3))
        i = len(chunks)

        for x in chunks:
            i -= 1
            n1, n2, n3 = get_digits(x)

            if n3 > 0:
                words.append(ONES[n3][0])
                if n3 > 1:
                    words.append(HUNDRED[1])
                else:
                    words.append(HUNDRED[0])

            if n2 > 1:
                words.append(TWENTIES[n2][0])
github savoirfairelinux / num2words / num2words / lang_HE.py View on Github external
def int2word(n):
    if n > 9999:  # doesn't yet work for numbers this big
        raise NotImplementedError()

    if n == 0:
        return ZERO[0]

    words = []

    chunks = list(splitbyx(str(n), 3))
    i = len(chunks)
    for x in chunks:
        i -= 1

        if x == 0:
            continue

        n1, n2, n3 = get_digits(x)

        if n3 > 0:
            if n3 <= 2:
                words.append(HUNDRED[n3][0])
            else:
                words.append(ONES[n3][0])
                words.append(HUNDRED[3][0])
github savoirfairelinux / num2words / num2words / lang_PL.py View on Github external
def _int2word(self, n):
        if n == 0:
            return ZERO[0]

        words = []
        chunks = list(splitbyx(str(n), 3))
        i = len(chunks)
        for x in chunks:
            i -= 1

            if x == 0:
                continue

            n1, n2, n3 = get_digits(x)

            if n3 > 0:
                words.append(HUNDREDS[n3][0])

            if n2 > 1:
                words.append(TWENTIES[n2][0])

            if n2 == 1:
github savoirfairelinux / num2words / num2words / lang_SR.py View on Github external
def _int2word(self, number, feminine=False):
        if number < 0:
            return ' '.join([self.negword, self._int2word(abs(number))])

        if number == 0:
            return ZERO[0]

        words = []
        chunks = list(splitbyx(str(number), 3))
        chunk_len = len(chunks)
        for chunk in chunks:
            chunk_len -= 1
            digit_right, digit_mid, digit_left = get_digits(chunk)

            if digit_left > 0:
                words.append(HUNDREDS[digit_left][0])

            if digit_mid > 1:
                words.append(TWENTIES[digit_mid][0])

            if digit_mid == 1:
                words.append(TENS[digit_right][0])
            elif digit_right > 0:
                is_feminine = feminine or SCALE[chunk_len][-1]
                gender_idx = int(is_feminine)
github savoirfairelinux / num2words / num2words / lang_KZ.py View on Github external
def _int2word(self, n, feminine=False):
        if n < 0:
            return ' '.join([self.negword, self._int2word(abs(n))])

        if n == 0:
            return ZERO

        words = []
        chunks = list(splitbyx(str(n), 3))
        i = len(chunks)
        for x in chunks:
            i -= 1

            if x == 0:
                continue

            n1, n2, n3 = get_digits(x)

            if n3 > 0:
                if n3 > 1:
                    words.append(ONES[n3])
                words.append(HUNDRED)

            if n2 == 1:
                words.append(TEN)
github savoirfairelinux / num2words / num2words / lang_CZ.py View on Github external
def _int2word(self, n):
        if n == 0:
            return ZERO[0]

        words = []
        chunks = list(splitbyx(str(n), 3))
        i = len(chunks)
        for x in chunks:
            i -= 1
            n1, n2, n3 = get_digits(x)

            if n3 > 0:
                words.append(HUNDREDS[n3][0])

            if n2 > 1:
                words.append(TWENTIES[n2][0])

            if n2 == 1:
                words.append(TENS[n1][0])
            elif n1 > 0 and not (i > 0 and x == 1):
                words.append(ONES[n1][0])