formatPercentage: Format a percentage.

View source: R/decimals.R

formatPercentageR Documentation

Format a percentage.

Description

The following rules are used:

  • percentage = 0%: '0'

  • 0% < percentage < 0.1%: '<0.1'

  • 99.9% < percentage < 100%: '>99.9'

  • percentage = 100%: '100'

  • missing value (NA) (class without valid data): '-'

  • other: 'x.x' (1 decimal)

Usage

formatPercentage(x, nDec = 1)

Arguments

x

Numeric vector with percentage(s)

nDec

Integer of length 1, number of decimals used to round the percentage, 1 by default.

Value

String with formatted percentage

Author(s)

Laure Cougnaud

See Also

Other decimals: getMaxNDecimalsData(), getMaxNDecimals(), getNDecimalsData(), getNDecimals()

Examples

xPerc <- c(NA, 0, 100, 99.95, 0.012, 34.768)
formatPercentage(x = xPerc)

inTextSummaryTable documentation built on Sept. 12, 2023, 5:06 p.m.