format_expenditure: Format expenditure

View source: R/format_expenditure.R

format_expenditureR Documentation

Format expenditure

Description

Formats a number as an expenditure, e.g. in £m, £k, $m etc. By default, expenditures are rounded to one decimal place in pound sterling, with values below 1 million formatted as £k, and above formatted as £m. This can be overridden by setting the format argument.

Usage

format_expenditure(value, format = NULL, currency = "£", dp = 1)

Arguments

value

A number representing an amount of money.

format

Specify as 'm' or 'k' to force the output in millions or thousands, respectively.

currency

A string representing a currency symbol. '£' by default.

dp

A number of decimal places to round expenditures to. By default, set to 1 decimal place.

Value

A character object representing an expenditure.

Examples

format_expenditure(36573436) # returns "£36.6m"
format_expenditure(356274) # returns "£356.3k"
format_expenditure(356274, format = "m") # returns "£0.4m"
format_expenditure(3562744, currency = "$") # returns "$3.6m"
format_expenditure(4654262.65, currency = "£", dp = 3) #returns "£4.654m"


moj-analytical-services/mojrap documentation built on July 30, 2023, 4:43 p.m.