dan dan - 2 months ago 20
R Question

Round down a numeric

I have

numeric
's like this one:

a <- -1.542045


And I want to round them down to 2 digits after the decimal point. So for this example the result will be
-1.55
.

With
signif(a,3)
I get 1.54 though.

Any idea?

Answer

I think you are looking for floor(a * 100) / 100.

Quick Test

a <- c(-1.542045, 1.542045)
floor(a * 100) / 100
# [1] -1.55  1.54