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
def _int2word(self, n, feminine=False): if n < 0: return ' '.join([self.negword, self._int2word(abs(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: words.append(TENS[n1][0]) elif n1 > 0: ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES words.append(ones[n1][0]) if i > 0: words.append(self.pluralize(x, THOUSANDS[i])) return ' '.join(words)
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'])