I am trying to replace all the float numbers in the string with the same numbers rounded to 2 decimal places. For example \"Hello23.898445World1.12212\" should
\"Hello23.898445World1.12212\"
We can use gsubfn
gsubfn
library(gsubfn) gsubfn("([0-9.]+)", ~format(round(as.numeric(x), 2), nsmall=2), str1) #[1] "Hello23.90World1.12"
str1 <- "Hello23.898445World1.12212"