Suppose my data looks like this:
df1 = data.frame(A=c(1000000.51,5000.33), B=c(0.565,0.794))
I want to use DataTables and have column A be (1,000,001 ; 5,000)
library(DT)
datatable(df1) %>% formatPercentage('B', 2) %>%
formatRound('A',digits = 0)
I know i can use scales
library(scales)
comma_format()(1000000)
but I'm not sure how to combine that with DataTables
Thanks!
You could use formatC
library(dplyr)
library(DT)
df1 %>%
mutate(A = formatC(round(A), format = "f", big.mark = ",", drop0trailing = TRUE),
B = paste0(formatC(100 * B, format = "f", digits = 2), "%")) %>%
datatable()
Which gives:
来源:https://stackoverflow.com/questions/29242011/add-comma-to-numbers-every-three-digits-in-datatable-r