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=str_pad(A, 8,'right', pad = "0")

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

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

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



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.