tokin/formatter.py
2025-02-16 22:16:06 +02:00

13 lines
336 B
Python

import fractions
from typesystem import Rational
def printValue(value, type):
if isinstance(type, Rational) and int(value) != value:
decimal = str(float(value))
if fractions.Fraction(decimal) == value:
print(f'{value}: {type} = {decimal}')
else:
print(f'{value}: {type}{decimal}')
else:
print(f'{value}: {type}')