Having a certain amount of digits in a data

Hi all,

I want to have a certain number of digits in all of the cells. I am currently using "str_pad" function from "stringr" library. This function generates numbers but does not cut them.

A=c(1,1.123,1.15545555555)
A=str_pad(A, 8,'right', pad = "0")

A
[1] "10000000" "1.123000" "1.15545555555"

This is what I got, but my desirable result is:

A
[1] "10000000" "1.123000" "1.155455"

Thanks,

Hi,

If you are looking at rounding then:

B <- round(A, 8)

It will round to 8 decimal places.

You can also use ceiling() and floor().

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.