R/decimal_place.R

decimal_place = function(x, k = 4, value = FALSE, dec = ",")
{
	cd = function(x, k)
	{
		s = sign(x)
		
		x = abs(x)
		
		nn = 1/10^k
		nk = paste0("<", format(nn, scientific=FALSE, decimal.mark = dec))
		
		if(is.na(x))
		{
			x = "" 
			#} else if(x == 0) {
			#	x = "0"
		} else if(x >= nn | x == 0) {
			x = x * s
			format(round(x, k), nsmall = k, decimal.mark = dec, scientific = FALSE) 
		} else nk #end if
	}#end function cd
	
	## numero total 
	nt = function(x) x
	
	if(value) out = sapply(round(x, k), nt) else out = sapply(x, cd, k = k)
	
	return(out)
	
}#end function casa_decimal
salah31416/toolbox documentation built on June 3, 2019, 6:59 p.m.