2 Decimal places, otherwise scientific notation
Arguments
- x
Vector of numbers
- decimal_places
Integer: Return this many decimal places.
- hi
Float: Threshold at or above which scientific notation is used.
- as_numeric
Logical: If TRUE, convert to numeric before returning. This will not force all numbers to print 2 decimal places. For example: 1.2035 becomes "1.20" if
as_numeric = 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.