Learn R Programming

lucr (version 0.2.0)

to_currency: Format numeric or integer values as currency values

Description

a formatter that lets you take numeric or integer values (12000) and convert them to strings that are currency-formatted ($12,000). Full control is available over the currency symbol, the size of delimited groups, the sign used to delimit groups, and decimal placement.

Usage

to_currency(x, currency_symbol = "£", symbol_first = TRUE, group_size = 3, group_delim = ",", decimal_size = 2, decimal_delim = ".")

Arguments

x
a numeric or integer vector containing values you want to currency-ify
currency_symbol
the symbol that identifies the currency. "£" by default.
symbol_first
whether the symbol goes at the beginning (TRUE) or end (FALSE) of the generated value. TRUE by default.
group_size
the size of delimited groups (2, 3, or 4 digits, say). Set to 3 by default.
group_delim
the delimiter for each group.
decimal_size
the number of digits after the decimal place. 2 by default but can be more (the Japanese Yen, for example, can go down to one rin, which is a thousandth of a Yen).
decimal_delim
the delimiter to use for sub-unit, decimal values. A period by default.

Examples

Run this code
to_currency(120000.03)
#[1] "£120,000.03"

Run the code above in your browser using DataLab