ddSci: Format Numbers for Printing

View source: R/ddSci.R

ddSciR Documentation

Format Numbers for Printing

Description

2 Decimal places, otherwise scientific notation

Usage

ddSci(x, decimal.places = 2, hi = 1e+06, asNumeric = FALSE)

Arguments

x

Vector of numbers

decimal.places

Integer: Return this many decimal places. Default = 2

hi

Float: Threshold at or above which scientific notation is used. Default = 1e06

asNumeric

Logical: If TRUE, convert to numeric before returning. Default = FALSE. This will not force all numbers to print 2 decimal places. For example: 1.2035 becomes "1.20" if asNumeric = FALSE, but 1.2 otherwise This can be helpful if you want to be able to use the output as numbers / not just for printing.

Details

Numbers will be formatted to 2 decimal places, unless this results in 0.00 (e.g. if input was .0032), in which case they will be converted to scientific notation with 2 significant figures. ddSci will return 0.00 if the input is exactly zero. This function can be used to format numbers in plots, on the console, in logs, etc.

Value

Formatted number

Author(s)

E.D. Gennatas

Examples

x <- .34876549
ddSci(x)
# "0.35"
x <- .00000000457823
ddSci(x)
# "4.6e-09"

egenn/rtemis documentation built on Oct. 28, 2024, 6:30 a.m.