Learn R Programming

priceR (version 1.0.2)

format_currency: Make numeric currency values human readable

Description

Make numeric currency values human readable

Usage

format_currency(amount, symbol, digits)

Value

A character vector

Arguments

amount

Price or vector of prices (character, numeric, or integer)

symbol

Symbol to prepend to amount (e.g. $) see: currency_characters()

digits

The number of decimal places. Set equal to 2 to include cents (defaults to 0 i.e. whole major currency units)

Examples

Run this code

# format_currency("2423562534234", "$")
# "$2,423,562,534,234"

# format_currency("2423562534234.876", "$", 0)
# "$2,423,562,534,234"

# format_currency("2423562534234.876", "$", 2)
# "$2,423,562,534,234.88"

# format_currency("2423562534234", "¥", 2)
# "¥2,423,562,534,234.00"

# format_currency() is vectorized and can accept vector arguments
format_currency(c("2423562534234", "20"), c("¥", "$"), c(1, 2))
# "¥2,423,562,534,234.0" "$20.00"

Run the code above in your browser using DataLab