npercent: neat representation of percentage

View source: R/numbers.R

npercentR Documentation

neat representation of percentage

Description

neat representation of percentage

Usage

npercent(
  percent,
  is_ratio = TRUE,
  digits = 1,
  show_plus_sign = TRUE,
  show_growth_factor = FALSE,
  show_bps = FALSE,
  is_decimal = NULL,
  plus_sign = NULL,
  factor_out = NULL,
  basis_points_out = NULL
)

Arguments

percent

an integer or double representing percentage

is_ratio

a Boolean variable. If the percent is raw, the value to set as TRUE. See examples below. If the percent variable is already pre-multiplied by 100 then the value to be set as FALSE.

digits

number of digits to round-off

show_plus_sign

a Boolean variable. If the percent is positive then setting show_plus_sign = TRUE, includes an explicit + sign before the percent

show_growth_factor

an optional Boolean variable.

show_bps

an optional parameter to get the percentage as basis points If the percent exceeds |100 readable factors. See examples below.

is_decimal

Deprecated. Use 'is_ratio' instead.

plus_sign

Deprecated. Use 'show_plus_sign' instead.

factor_out

Deprecated. Use 'show_growth_factor' instead.

basis_points_out

Deprecated. Use 'show_bps' instead.

Value

String representation of the percentages.

Examples

# Formatting 22.3%
npercent(0.223, is_ratio = TRUE, digits = 1)
npercent(22.3, is_ratio = FALSE, digits = 1)
# Formatting percentages with growth factors
npercent(c(-4.01, 2.56), is_ratio = TRUE, show_growth_factor = TRUE)
# Formatting percentages as basis points
npercent(
  c(-1, -0.5, -0.1, -0.01, 0, 0.01, 0.1, 0.5, 1),
  is_ratio = TRUE, show_bps = TRUE
)

neatR documentation built on Jan. 31, 2026, 5:07 p.m.