#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 金额英文大写转换 """ from num2words import num2words import math def amount_to_english_words(amount: float) -> str: """ 将金额转换为英文大写 Args: amount: 金额数字,如 14488 Returns: 英文大写字符串,如 "FOURTEEN THOUSAND FOUR HUNDRED AND EIGHTY-EIGHT" """ if amount is None or amount < 0: return '' # 四舍五入到整数 amount_int = round(amount) # 转换为英文单词并大写 words = num2words(amount_int, lang='en') return words.upper().replace('-', ' ').replace(',', '') def calculate_payment_split(total_amount: float) -> tuple: """ 计算30%和70%的付款金额 规则:30%向上取整,70% = 总金额 - 30% 确保 30% + 70% = 总金额 Returns: (deposit_30, balance_70) """ total_int = round(total_amount) deposit_30 = math.ceil(total_int * 0.30) balance_70 = total_int - deposit_30 return deposit_30, balance_70 def format_say_us_only(amount: float) -> str: """ 格式化为 "SAY US {大写} only" Args: amount: 金额数字 Returns: 如 "SAY US FOURTEEN THOUSAND FOUR HUNDRED AND EIGHTY EIGHT only" """ words = amount_to_english_words(amount) return f"SAY US {words} only" if __name__ == '__main__': # 测试 print(format_say_us_only(14488)) print(format_say_us_only(4346.4)) print(format_say_us_only(10141.6))