API Reference › Math › Math.round
method

Math.round

Math.round(x) -> int

Takes a fixed value and returns the nearest int, with halves rounding up: Math.round(2.5) is 3 and Math.round(2.4) is 2. Choose it over Math.floor when you want the closest whole value rather than always the lower one — snapping a smoothly-moving sprite to a pixel, or reporting a fractional total as a clean number.

Parameters

xthe fixed value to round to nearest

Example

program SnapToPixel {
  var smooth_x: fixed = 10.5

  handler Draw phase Render {
    let px = Math.round(smooth_x)   # 11
  }
}
← All symbols