Garry's Mod Wiki

math.SnapTo

  number math.SnapTo( number input, number snapTo )

Just Added

This was just added in the latest version (2022.06.08). It might only be available on the Dev Branch right now.

Description

Snaps a number to the closest multiplicative of given number. See also Angle:SnapTo.

Arguments

1 number input
The number to snap.
2 number snapTo
What to snap the input number to.

Returns

1 number
The clamped value.

Example

Example usage

print( math.SnapTo( 0, 15 ) ) print( math.SnapTo( 10, 15 ) ) print( math.SnapTo( 20, 15 ) ) print( math.SnapTo( 22.2, 15 ) ) print( math.SnapTo( 22.5, 15 ) ) print( math.SnapTo( 43, 15 ) )
Output:
0 15 15 15 30 45