Feat: dirty way to get decimal approx of a function

This commit is contained in:
Bertrand Benjamin 2019-10-14 22:26:51 +02:00
parent a3f7efca12
commit 0abd80655a

View File

@ -16,6 +16,7 @@ from ...core.arithmetic import gcd
from ...core.random.int_gene import filter_random
from ...core.MO import MO, MOnumber
from ...core.MO.fraction import MOFraction
from random import random
__all__ = ["Integer", "Decimal"]
@ -242,6 +243,20 @@ class Fraction(Token):
def denominator(self):
return self._mo.denominator
@property
def decimal(self):
""" return decimal approximation of the fraction
:example:
>>> f = Fraction("3/4")
>>> f.decimal
<Decimal 0.75>
>>> f = Fraction("1/3")
>>> f.decimal
<Decimal 0.3333333333333333333333333333>
"""
return Decimal(_Decimal(self._mo.numerator._value) / _Decimal(self._mo.denominator._value))
# -----------------------------
# Reglages pour 'vim'