let's say I have a value that is between 0
and 1
. I have a grid size and would like the value to snap to grid. so if grid size is equal to two I would like to switch from 0
to 1
if grid size equal to three this would switch from 0
, 0.5
to 1
if it's four 0
, 0.33
, 0.66
, 1
and so on...
CodePudding user response:
Assuming the language you use has a round
function that rounds to the nearest integer, and calling v
the value and n
the grid size:
round(v * (n-1)) / (n-1)