1 | initial version |
You can use the method nearby_rational which works for real numbers. If you do have a symbolic expression, you first have to take a numerical approximation as in
sage: pi.n().nearby_rational()
The term pi may be replaced by any symbolic expression.