DescTools (version 0.99.14)

Ndec: Count Decimal Places of a Number

Description

Returns the number of decimal places in the vector x. x must be a character and contain formatted numbers.

Usage

Ndec(x)
Prec(x)

Arguments

x
is a character vector containing formatted numbers

Value

  • an integer value.

Details

The function is currently defined as: Ndec <- function(x) { stopifnot(class(x)=="character") res <- rep(0, length(x)) x <- gsub(pattern="[eE].+$", rep="", x=x) res[grep("\.",x)] <- nchar( sub("^.+[.]","",x) )[grep("\.",x)] return(res) }

See Also

format.info, Frac

Examples

Run this code
x <- c("0.0000", "0", "159.283", "1.45e+10", "1.4599E+10" )
Ndec(x)
Prec(as.numeric(x))

Run the code above in your browser using DataCamp Workspace