I get very weird fractions in sympy.
I have no clue why it is given me these unusual fractions
To answer your question:
Rational("0.1")
# out: 1 / 10
Rational(0.1)
# out: 3602879701896397/36028797018963968
The second output happens because 0.1
is a number of type float, hence it is inherently inaccurate.
sympy manual: https://docs.sympy.org/latest/explanation/gotchas.html#python-numbers-vs-sympy-numbers
in short:
you type Rational(0.1)
, then sympy has to test a float.
but Rational("0.1")
works. str keep the number.
if you don't like this.
First convert it to sympy's type Integer(1)/10
. Also works.