24 """ Portuguese helper for nice_number 26 This function formats a float to human understandable functions. Like 27 4.5 becomes "4 e meio" for speech and "4 1/2" for text 30 number (int or float): the float to format 31 speech (bool): format for speech (True) or display (False) 32 denominators (iter of ints): denominators to use, default [1 .. 20] 34 (str): The formatted string. 40 return str(round(number, 3))
42 whole, num, den = result
49 return '{} {}/{}'.format(whole, num, den)
54 den_str = _FRACTION_STRING_PT[den]
59 return_string =
'um {}'.format(den_str)
62 return_string =
'{} {}'.format(num, den_str)
66 return_string =
'{} e {}'.format(whole, den_str)
70 return_string =
'{} e {} {}'.format(whole, num, den_str)
79 Convert a number to it's spoken equivalent 80 For example, '5.2' would return 'cinco virgula dois' 82 num(float or int): the number to pronounce (under 100) 83 places(int): maximum decimal places to speak 85 (str): The pronounced number 97 tens = int(num - int(num) % 10)
98 ones = int(num - tens)
99 result += _NUM_STRING_PT[tens]
101 result +=
" e " + _NUM_STRING_PT[ones]
103 result += _NUM_STRING_PT[int(num)]
108 if not num == int(num)
and places > 0:
111 while int(num * place) % 10 > 0
and places > 0:
112 result +=
" " + _NUM_STRING_PT[int(num * place) % 10]
120 Format a time to a comfortable human format 121 For example, generate 'cinco treinta' for speech or '5:30' for 124 dt (datetime): date to format (assumes already in local timezone) 125 speech (bool): format for speech (default/True) or display (False)=Fal 126 use_24hour (bool): output in 24-hour/military or 12-hour format 127 use_ampm (bool): include the am/pm for 12-hour format 129 (str): The formatted time string 133 string = dt.strftime(
"%H:%M")
137 string = dt.strftime(
"%I:%M %p")
140 string = dt.strftime(
"%I:%M")
166 elif dt.minute == 40:
169 elif dt.minute == 45:
172 elif dt.minute == 50:
175 elif dt.minute == 55:
183 speak +=
"meia noite" 187 elif hour == 1
or hour == 13:
189 elif hour == 2
or hour == 14:
198 speak +=
" e um quarto" 202 speak +=
" menos um quarto" 210 if minute == 0
and not use_ampm:
215 if hour > 0
and hour < 6:
216 speak +=
" da madrugada" 217 elif hour >= 6
and hour < 12:
219 elif hour >= 13
and hour < 21:
221 elif hour != 0
and hour != 12: