dol <- function(x, digits = 0L) {
magnitude = log10(x)
if (magnitude > 12) {
suffix <- 'trillion'
x <- x / 1e12
} else if (magnitude > 9) {
suffix = 'billion'
x <- x / 1e9
} else if (magnitude > 6) {
suffix <- 'million'
x <- x / 1e6
} else {
return(sprintf('$%s',
prettyNum(x, big.mark = ',')))
}
sprintf('$%s %s',
prettyNum(round(x, digits = digits),
big.mark = ','),
suffix)
}
pct <- function(x, digits = 0L) {
sprintf('%s percent',
prettyNum(round(x, digits = digits),
big.mark = ','))
}
num <- function(x, digits = 0L) {
prettyNum(round(x, digits = digits),
big.mark = ',')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.