currency: Transform to currency

Description Usage Arguments Details Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
as.currency(x, currency_symbol = Sys.localeconv()["int_curr_symbol"], ...)

is.currency(x)

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

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

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

as_symbol

try to format and print using currency symbols instead of text

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
money <- as.currency(c(0.25, 2.5, 25, 25000))
money
sum(money)
max(money)
mean(money)

format(money, currency_symbol = "USD")
format(money, currency_symbol = "EUR", decimal.mark = ",")
format(money, currency_symbol = "EUR", as_symbol = TRUE)

as.currency(2.5e+04)

cleaner documentation built on June 13, 2021, 5:06 p.m.