API Reference › Math › Math.floor
method

Math.floor

Math.floor(x) -> int

Takes a fixed value and returns the largest int not greater than it — rounding toward negative infinity, so Math.floor(2.7) is 2 and Math.floor(-0.2) is -1. This is the fixed-to-int conversion you reach for when turning a smooth position into a whole tile or pixel index. It is the same operation as the bare floor(x).

Parameters

xthe fixed value to round down

Example

program TileIndex {
  const TILE_SIZE: fixed = 16.0

  var world_x: fixed = 40.5

  handler Locate phase Update {
    let column = Math.floor(world_x / TILE_SIZE)   # 2
  }
}
← All symbols