Learn R Programming

clean (version 1.1.0)

currency: Transform to currency

Description

Transform input to a currency. The actual values are numeric, but will be printed as formatted currency values.

Usage

as.currency(x, currency_symbol = Sys.localeconv()["int_curr_symbol"],
  ...)

is.currency(x)

# S3 method for currency print(x, decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark == ",", ".", ","), ...)

# S3 method for currency format(x, currency_symbol = attributes(x)$currency_symbol, decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark == ",", ".", ","), ...)

Arguments

x

input

currency_symbol

the currency symbol to use, which defaults to the current system locale setting (see Sys.localeconv)

...

other parameters passed on to methods

decimal.mark

symbol to use as a decimal separator, defaults to getOption("OutDec")

big.mark

symbol to use as a thousands separator, defaults to a dot if decimal.mark is a comma, and a comma otherwise

Details

Printing currency will always have a currency symbol followed by a space, 2 decimal places and is never written in scientific format (like 2.5e+04).

Examples

Run this code
# NOT RUN {
money <- as.currency(c(0.25, 2.5, 25, 25000))
money
sum(money)
max(money)
mean(money)

format(money, currency_symbol = "$")
format(money, currency_symbol = "<U+20AC>", decimal.mark = ",")

as.currency(2.5e+04)
# }

Run the code above in your browser using DataLab