jorgeassis
2/1/2020 - 12:01 PM

Get the number of decimals of a number

Get the number of decimals of a number

decimals <- function(x) {
  if ((x %% 1) != 0) {
    nchar(strsplit(sub('0+$', '', as.character(x)), ".", fixed=TRUE)[[1]][[2]])
  } else {
    return(0)
  }
}