Nix13

Number short

Sep 24th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. short = {0: '',
  2.          1: 'тыс.',
  3.          2: 'млн.',
  4.          3: 'млрд.',
  5.          4: 'трлн.',
  6.          5: 'тлрд.',
  7.          6: 'квадрлн.',
  8.          7: 'квадрд.',
  9.          8: 'квинтлн.',
  10.          9: 'квинтрд.',
  11.          10: 'секстлн.',
  12.          11: 'секстрд.',
  13.          12: 'септлн.',
  14.          13: 'септрд.',
  15.          14: 'октлн.',
  16.          15: 'октрд.',
  17.          16: 'нонилн.',
  18.          17: 'нонирд.'}
  19.  
  20.  
  21. def to_human(money, after_round=True, round_number=2, sep='\''):
  22.     money = str(money).split(sep='.')
  23.     before = money[0]
  24.     if len(money) > 1:
  25.         after = money[1]
  26.     index = -1
  27.     string = ''
  28.     for i in before[::-1]:
  29.         if index < 2:
  30.             string += i
  31.             index += 1
  32.         else:
  33.             string += sep
  34.             string += i
  35.             index = 0
  36.     return f'{string[::-1]}{f".{after if not after_round else after[:round_number]}" if len(money) > 1 else ""}'
  37.  
  38.  
  39. numbers = ['100', '1000', '10000', '100000', '1000000', '10000000', '100000000', '1000000000', '10000000000',
  40.            '100000000000', '1000000000000']
  41. sep = "'"
  42. for i in numbers:
  43.     print(f'{to_human(i).split(sep=sep)[0]} {short[len(i) // 3] if len(i) % 3 != 0 else short[(len(i) // 3) - 1]}')
Advertisement
Add Comment
Please, Sign In to add comment