as_fraction: Convert a Decimal to an Approximate Fraction

Description Usage Arguments Value Examples

View source: R/fractions.R

Description

The as_fraction function takes a numeric input and converts it to a fraction. The input is first rounded to the desired level of precision (entered as a value between 1 and 7).

Usage

1
as_fraction(number, precision = 3, improper = TRUE)

Arguments

number

The decimal you want to convert to a fraction.

precision

The number of digits to round the decimal to before trying to convert the result to a fraction. Must be greater than 1 but less than 8.

improper

Logical. Should the fraction be a returned as an improper fraction or a proper fraction? Defaults to TRUE.

Value

A formatted list printed with print.fraction(). The list includes four elements:

Examples

1
2
3
4
as_fraction(3.2454)
as_fraction(3.2454, 2, TRUE)
as_fraction(3.2454, 2, FALSE)
as_fraction(3.2454, 1, FALSE)

mrdwab/mathrrr documentation built on July 20, 2020, 11:14 p.m.