def nice_number(number, lang="en-us", speech=True, denominators=None): """Format a float to human readable functions This function formats a float to human understandable functions. Like 4.5 becomes 4 and a half for speech and 4 1/2 for text Args: number (int or float): the float to format lang (str): code for the language to use speech (bool): format for speech (True) or display (False) denominators (iter of ints): denominators to use, default [1 .. 20] Returns: (str): The formatted string. """ # Convert to spoken representation in appropriate language lang_lower = str(lang).lower() if lang_lower.startswith("en"): return nice_number_en(number, speech, denominators) elif lang_lower.startswith("pt"): return nice_number_pt(number, speech, denominators) elif lang_lower.startswith("it"): return nice_number_it(number, speech, denominators) elif lang_lower.startswith("fr"): return nice_number_fr(number, speech, denominators) elif lang_lower.startswith("sv"): return nice_number_sv(number, speech, denominators) elif lang_lower.startswith("de"): return nice_number_de(number, speech, denominators) elif lang_lower.startswith("hu"): return nice_number_hu(number, speech, denominators) elif lang_lower.startswith("nl"): return nice_number_nl(number, speech, denominators) # Default to the raw number for unsupported languages, # hopefully the STT engine will pronounce understandably. return str(number)
def nice_number(number, lang="en-us", speech=True, denominators=None): """Format a float to human readable functions This function formats a float to human understandable functions. Like 4.5 becomes 4 and a half for speech and 4 1/2 for text Args: number (int or float): the float to format lang (str): code for the language to use speech (bool): format for speech (True) or display (False) denominators (iter of ints): denominators to use, default [1 .. 20] Returns: (str): The formatted string. """ # Convert to spoken representation in appropriate language lang_lower = str(lang).lower() if lang_lower.startswith("en"): return nice_number_en(number, speech, denominators) elif lang_lower.startswith("pt"): return nice_number_pt(number, speech, denominators) elif lang_lower.startswith("it"): return nice_number_it(number, speech, denominators) elif lang_lower.startswith("fr"): return nice_number_fr(number, speech, denominators) elif lang_lower.startswith("sv"): return nice_number_sv(number, speech, denominators) elif lang_lower.startswith("de"): return nice_number_de(number, speech, denominators) # Default to the raw number for unsupported languages, # hopefully the STT engine will pronounce understandably. return str(number)