nearbyint

Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead.

  1. D nearbyint(D x, RoundingMode mode)
  2. D nearbyint(D x)
    D
    nearbyint
    (
    D
    )
    (
    auto const ref D x
    )

Throws

InvalidOperationException if x is signaling NaN

Special values

xnearbyint(x)
NaNNaN
±∞±∞
±0.0±0.0

Examples

assert(nearbyint(decimal32("1.2"), RoundingMode.tiesToEven) == 1);
assert(nearbyint(decimal64("2.7"), RoundingMode.tiesToAway) == 3);
assert(nearbyint(decimal128("-7.9"), RoundingMode.towardZero) == -7);
assert(nearbyint(decimal128("6.66")) == 7);

Meta