scales (version 0.2.4)

dollar_format: Currency formatter: round to nearest cent and display dollar sign.

Description

The returned function will format a vector of values as currency. Values are rounded to the nearest cent, and cents are displayed if any of the values has a non-zero cents and the largest value is less than largest_with_cents which by default is 100000.

Usage

dollar_format(largest_with_cents = 1e+05)

dollar(x)

Arguments

largest_with_cents
the value that all values of x must be less than in order for the cents to be displayed
x
a numeric vector to format

Value

  • a function with single paramater x, a numeric vector, that returns a character vector

Examples

Run this code
dollar_format()(c(100, 0.23, 1.456565, 2e3))
dollar_format()(c(1:10 * 10))
dollar(c(100, 0.23, 1.456565, 2e3))
dollar(c(1:10 * 10))
dollar(10^(1:8))

Run the code above in your browser using DataCamp Workspace