makePercentage: Convert a number or a string to a percentage.

View source: R/makePercentage.R

makePercentageR Documentation

Convert a number or a string to a percentage.

Description

Takes an object x of class "character" or "numeric". Returns an object of class "character" in which the number is expressed as a percentage.

Usage

makePercentage(x, dp = 0)

Arguments

x

Object of class "character," "integer," or "numeric."

dp

Integer specifying the number of decimal places in the returned string.

Details

By default, the returned string will have no decimal digits: it will be "57%", not "57.0%". But if dp is greater than 0, the returned string will always have dp decimal places.

Value

A string, e.g., "57%".

Examples

makePercentage(.5)            # "50%"
makePercentage(.555)          # "56%"
makePercentage(.555, dp = 4)  # "55.5000%"
makePercentage(5)             # "500%"
makePercentage(5, dp = 2)     # "500.00%"

makePercentage(1:3)           # "100%" "200%" "300%"


jbullock35/Bullock documentation built on April 1, 2022, 6:21 p.m.