# Transform a floating point number into a rational: exact float2rational

### 5.7.1 Transform a floating point number into a rational: exact float2rational

Rational numbers can be approximated by floating point numbers, but since floating point numbers are not exact, they can’t typically be converted back to the original rational number. However, the float2rational command will try convert a floating point to a nearby rational number.
exact is a synonym for float2rational.

- float2rational takes one argument:
  d, a floating point number.
- float2rational(d) returns a rational number q close to d; namely such that |d−q|<epsilon, where epsilon is defined in the cas configuration (Cfg menu, see Section 2.5.7, item 9) or with the cas_setup command (see Section 2.5.10).

#### Examples.

- Input:
  float2rational(0.3670520231)
  Output (when epsilon=1e-10):

  127
  346

- Input:
  evalf(363/28)
  Output:

  12.9642857143

- Input:
  float2rational(12.9642857143)
  Output:

  363
  28

- If two representations are mixed, for example:
  Input:
  1/2+0.7
  the rational is converted to a float.
  Output:

  1.2

- Input:
  1/2+float2rational(0.7)
  Output:

  6
  5