R/round2.R

Defines functions round2

Documented in round2

#' Round numbers following normal convention.
#' 
#' @param x A numeric scalar.
#' @param n The order for the rounding.
#' @return The result that would be equivalent to Matlab.
#' @examples
#' 

round2 = function(x,n) {
  # where 0.5 rounds up to 1 and 0.4 to 0
  posneg = sign(x)
  z = abs(x)*10^n
  z = z + 0.5
  z = trunc(z)
  z = z/10^n
  z*posneg
}
KevinKotze/tsm documentation built on Oct. 6, 2022, 12:22 a.m.