round2_fmt: Rounding and Formatting Numbers

round2_fmtR Documentation

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, ...)

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).

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.

Author(s)

Adapted from exams package by R. Schwabe et al.

See Also

round2, fmt from the exams package.


exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.