﻿ ToFraction – Algosim documentation
Algosim documentation: ToFraction

# ToFraction

Converts a number to an approximating rational number.

## Syntax

• `ToFraction(x)`

• `x` is a number

• `ToFraction(r)`

• `r` is a structure of type `RationalNumber`

• `ToFraction(a[, [b, ...]])`

• `a`, `b`, `...` are the numbers of a continued fraction representation

• `ToFraction(L)`

• `L` is a list containing the numbers of a continued fraction representation

## Description

• If `x` is a number, then `ToFraction(x)` is a rational number equal to or very nearly equal to `x`.

• If `r` is a structure of type `RationalNumber`, then `ToFraction(r)` is the rational number that `r` represents.

• If `a, b, ...` is the list of numbers of a continued fraction representation, or if `L` is a list with these numbers, then `ToFraction(a, b, ...)` and `ToFraction(L)` both return the rational number that the continued fraction represents.

## Examples

`ToFraction(5.72)`
`143/25	(=5.72)`
`ToFraction(π)`
`2549491779/811528438	(=3.14159265359)`
`ToFraction(5, 1, 2, 1, 1, 3)`
`143/25	(=5.72)`