Learn R Programming

crmPack (version 2.0.0)

h_format_number: Conditional Formatting Using C-style Formats

Description

[Experimental]

This helper function conditionally formats a number with formatC() function using "E" format and specific number of digits as given by the user. A number is formatted if and only if its absolute value is less than 0.001 or greater than 10000. Otherwise, the number is not formatted. Additionally, custom prefix or suffix can be appended to character string with formatted number, so that the changes are marked.

Usage

h_format_number(x, digits = 5, prefix = "", suffix = "")

Value

Either formatted x as string or unchanged x if the formatting condition is not met.

Arguments

x

(number)
a number to be formatted.

digits

(function)
the desired number of significant digits.

prefix

(string)
a prefix to be added in front of the formatted number.

suffix

(string)
a suffix to be appended after the formatted number.

Examples

Run this code
h_format_number(50000)
h_format_number(50000, prefix = "P", suffix = "S")

Run the code above in your browser using DataLab