I'm not sure if you can get that with nsimplify(). I tried playing
with the tolerance and rational_conversion arguments, but it either
tries to be smart and reconstruct the original fraction, or it gives
the exact base-2 fraction represented by the float
(4793116746272885/1125899906842624).

If I understand correctly, you want to take this decimal

>>> (Integer(149)/35).evalf()
4.25714285714286

and re-interpret it as a base-10 rational. You can convert it to a
string and use Rational(), like

>>> Rational(str((Integer(149)/35).evalf()))
212857142857143/50000000000000

To get the version you mentioned, you should use

>>> (Integer(149)/35).evalf(16)
4.257142857142857
>>> Rational(str((Integer(149)/35).evalf(16)))
4257142857142857/1000000000000000

Aaron Meurer

On Mon, Aug 10, 2020 at 1:56 PM Paul Royik <[email protected]> wrote:
>
> nsimplify((Integer(149)/25).evalf()) outputs 149.25, as expected
> nsimplify((Integer(149)/35).evalf()) outputs 149/35, which is not expected as 
> it is repeating decimal.
> How to make it perform approximation to given precision: 
> 4257142857142857/10**15 ?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/facbc559-651d-4ff2-a1e0-4ae9194b5ac5o%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6KuCO0FUov_bewF2p5YBvhu-O_US2LYoy9eMJR7xo5kOg%40mail.gmail.com.

Reply via email to