fcvt | R Documentation |
Converts a number to a string containing either a floating point or a fractional number.
Note that a repeating or recurring decimal, which is a number whose decimal representation becomes periodic,
can also be expressed as a rational number. For example, \frac{1}{3}=0.333333333...=0.\overline{3}
.
It is the workhorse used in num2str
.
If denom
is negative then always decimal point numbers are used (default).
If denom
is zero then a mix of decimal point and fractional numbers are used (whatever is shorter).
If denom
is one then fractional numbers are used except for integers.
If denom
is larger than one, then the denominator is set to denom
if possible.
fcvt(x, nsmall = 15, plus = FALSE, denom = -1)
x |
numeric: numbers to convert |
nsmall |
integer: number of significant digits for the mantissa/significand (default: |
plus |
logical: for positive numbers a plus sign should be used (default: |
denom |
integer: denominator for a fractional number |
A character.
x1 <- c(NA, NaN, -Inf, Inf, 0, pi*10^(-20:20))
fcvt(x1)
x2 <- c(-0.36, 3.6, -30.6, 0.36)
fcvt(x2)
x3 <- c((0:16)/8, 1/3)
fcvt(x3) # as floating point number, equals denom=-1
fcvt(x3, denom=0) # as floating point or fractional number
fcvt(x3, denom=1) # as fractional number except for integers
fcvt(x3, denom=8) # as fractional number with denominator denom if possible
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.