Skip to content

Instantly share code, notes, and snippets.

@amitkot
Last active December 12, 2018 10:58
Show Gist options
  • Save amitkot/f14971be9356b91f1a42060a177f74d7 to your computer and use it in GitHub Desktop.
Save amitkot/f14971be9356b91f1a42060a177f74d7 to your computer and use it in GitHub Desktop.
Fun with decimals, useful for big numbers
from decimal import Decimal
import re
def ddiff(str):
numbers = re.findall(r'\d+', str)
print(f'0: {numbers[0]}')
print(f'1: {numbers[1]}')
print(f'diff: {Decimal(numbers[0]) - Decimal(numbers[1])}')
def dsum():
items = []
while True:
num = input('Enter number: ')
if not num: break
items.append(Decimal(num))
print('---')
print(f'Numbers: {items}')
print(f'Sum: {sum(items)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment