Skip to main content

snapped

Function snapped 

pub fn snapped(x: &Variant, step: &Variant) -> Variant
Expand description

Returns the multiple of step that is the closest to x. This can also be used to round a floating-point number to an arbitrary number of decimals.

The returned value is the same type of Variant as step. Supported types: int, float, Vector2, Vector2i, Vector3, Vector3i, Vector4, Vector4i.

snapped(100, 32)  # Returns 96
snapped(3.14159, 0.01)  # Returns 3.14

snapped(Vector2(34, 70), Vector2(8, 8))  # Returns (32, 72)

See also [method ceil], [method floor], and [method round].

Note: For better type safety, use [method snappedf], [method snappedi], snapped, snapped, snapped, snapped, snapped, or snapped.