This seems like it should be a fairly easy problem to solve but I am having some trouble locating an answer.
I have a vector which contains long decimals and I want
trunc(x*10^4)/10^4
yields 0.1234 like expected.
0.1234
More generally,
trunc <- function(x, ..., prec = 0) base::trunc(x * 10^prec, ...) / 10^prec; print(trunc(0.123456789, prec = 4) # 0.1234 print(trunc(14035, prec = -2), # 14000