#' How many significant decimals places are in a number
#'
#' @param x
#' @param decimal.char
#'
#' @return
#' @export
#'
#' @examples
num_decimals <- function(x, decimal.char=".", digits = 4) {
if(!is.numeric(x)) return(0)
x <- round(x, digits = digits)
if (abs(x - round(x)) > .Machine$double.eps^0.5) {
nchar(strsplit(sub('0+$', '', as.character(x)), decimal.char, fixed=TRUE)[[1]][[2]])
} else {
return(0)
}
}
#' Max number of significant decimal places are in a vector
#'
#' @param x
#' @param decimal.char
#' @param digits
#'
#' @return
#' @export
#'
#' @examples
max_num_decimals <- function(x, decimal.char = ".", digits = 4) {
if(!is.numeric(x)) return(0)
max(sapply(x,num_decimals, decimal.char=decimal.char, digits=digits))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.