Rationalize

WMA link


Rationalize[x]

converts a real number x to a nearby rational number with small denominator.

Rationalize[x, $d_x$]

finds the rational number lies within $d_x$ of x.

For negative x, -Rationalize[-x] == Rationalize[x] which gives symmetric results:

Not all numbers can be well approximated.

Find the exact rational representation of N[Pi]

Piecewise
RealAbs