Learn R Programming

neatR (version 0.2.0)

nnumber: neat representation of numbers

Description

neat representation of numbers

Usage

nnumber(
  number,
  digits = 1,
  unit = "custom",
  unit.labels = list(thousand = "K", million = "Mn", billion = "Bn", trillion = "Tn"),
  prefix = "",
  suffix = "",
  thousand.separator = ","
)

Value

String representation of numbers with suffix denoting K for thousands, Mn for millions, Bn for billions, Tn for trillions. A number lower than thousand is represented as it is.

Arguments

number

an integer or double.

digits

number of digits to round-off. Default value is 1.

unit

unit to which the number to be converted. See examples below.

unit.labels

a vector of strings (optional) that gives the unit label for thousand, million, billion and trillion.

prefix

a string (optional) that can be prepended to the formatted number.

suffix

a string (optional) that can be appended at the end of the formatted number.

thousand.separator

a character (optional) that can be used to chunk thousands to display large numbers. Default is set as comma, dot, comma or underscore can be used.

Examples

Run this code
x <- c(10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000)
nnumber(x)
nnumber(123456789.123456, digits = 1)
nnumber(123456789.123456, digits = 1, unit = 'Mn', prefix = '$')

Run the code above in your browser using DataLab