Round v0.1.0

Source
Rounds to the nearest integer value.

Package: Math

Signature

func Round(x: float64) -> float64;
func Round(x: float32) -> float32;

Parameters

NameTypeDescription
xfloat64 / float32The value to round.

Returns

The nearest integer value to x, still represented as a floating-point number. A tie rounds away from zero: Round(2.5) is 3.0 and Round(-2.5) is -3.0. Infinities and NaNs pass through unchanged.

Example

import Math::Round;

func Main() -> int {
    let a = Round(2.5);  // 3.0
    let b = Round(-2.5); // -3.0
    let c = Round(2.4);  // 2.0
    return 0;
}

See also

  • Math — the package overview
  • Floor — round down
  • Ceil — round up
  • Trunc — round toward zero