ludic/docs/language/math/math-round.md

821 B

id name category kind tokens sig tip order ns member
math-round Math.round math namespace-method Math.round Math.round(x) -> int Round a fixed value to the nearest whole int. 7 Math round

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:

  • x — the fixed value to round to nearest
program SnapToPixel {
  let smooth_x: fixed = 10.5

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