def round_to_template(num: decimal.Decimal, example: decimal.Decimal) -> decimal.Decimal: """ 将 num 四舍五入到 example 所在的位数 :param num: :param example: 必须含有 1,比如 decimal.Decimal('0.01')、decimal.Decimal('0.000001000') :return: """ example = str(example) if '1' not in example: raise ValueError('example 必须包含 1') # 去除小数点 example = example.replace('.', '') return round(num, example.index('1'))
from decimal import Decimal, ROUND_FLOOR while True: try: a = Decimal(input()) except EOFError: break if 0 <= a <= 100: a = a * 9 / 10 + 8 elif 100 < a <= 500: a = a * 8 / 10 else: a = a * 6 / 10 a = str(a) try: a = float(a[:a.index(".")+3]) except ValueError: pass print('${:.2f}'.format(a))