Learn R Programming

exams.forge (version 1.0.11)

round2_fmt: Rounding and Formatting Numbers

Description

These functions provide rounding and formatting similar to exams::round2 and exams::fmt. round2 performs half-up rounding with a small offset to avoid rounding errors. fmt formats numbers as character strings with a specified number of decimal places.

Usage

round2(x, digits = 0)

fmt(x, digits = 2L, zeros = digits < 4L, ...)

Value

round2 returns a numeric vector rounded to the specified number of digits. fmt returns a character vector with numbers formatted as strings with the requested number of decimal places.

Arguments

x

Numeric vector to be rounded or formatted.

digits

Integer, number of decimal places. Default is 0 for round2, 2 for fmt.

zeros

Logical, whether to keep trailing zeros. Default is TRUE if digits < 4 (fmt only).

...

Additional arguments passed to format() (fmt only).

Author

Adapted from exams package by R. Schwabe et al.

See Also

round2, fmt from the exams package.