Frac() returns the fractional part of a numeric value. MaxDigits() return the number of digits in x.
Ndec() returns the number of decimals.
Prec() returns the precision of a number x.

Frac(x, dpwr = NA)
MaxDigits(x)
Ndec(x)
Prec(x)

Arguments

x

the numeric value (or a vector of numerics), whose fractional part is to be calculated.

dpwr

power of 10 for a factor z, the fractional part will be multiplied with. The result will be returned rounded to integer. Defaults to NA and will then be ignored.

Author

Andri Signorell <andri@signorell.net>

Examples

x <- rnorm(5)*100
x
#> [1]   77.42424  -92.65176   79.79464 -119.76835 -159.16203
Frac(x)
#> [1] 0.4242413 0.6517609 0.7946360 0.7683459 0.1620348

# multiply by 10^4
Frac(x, dpwr=4)
#> [1] 4242 6518 7946 7683 1620

MaxDigits(c(1.25, 1.8, 12.0, 1.00000))
#> [1] 2

x <- c("0.0000", "0", "159.283", "1.45e+10", "1.4599E+10" )
Ndec(x)
#> [1] 4 0 3 2 4
Prec(as.numeric(x))
#> [1] 0.001