# Thread: Ext.Number.snap - can someone explain in details?

1. ## Answered: Ext.Number.snap - can someone explain in details?

Hi all,

I am new to extjs and am very curious how and why is this "Ext.Number.snap" used for? I read the documentation several times, but still it's not that clear to me.

Thank you in advance and do please excuse me for the stupid question.

Regards

2. It's for implementing a 'snap to grid'. You can think of it as a sort of advanced rounding function.

You could also think of it as a slider with discrete intervals.

e.g. For percentages with intervals of 10% you might use:

Code:
```Ext.Number.snap(3, 10, 0, 100); // => 0
Ext.Number.snap(13, 10, 0, 100); // => 10
Ext.Number.snap(17, 10, 0, 100); // => 20
Ext.Number.snap(21, 10, 0, 100); // => 20```
This example is simply rounding to the nearest 10, constrained between 0 and 100.

3. It's for implementing a 'snap to grid'. You can think of it as a sort of advanced rounding function.

You could also think of it as a slider with discrete intervals.

e.g. For percentages with intervals of 10% you might use:

Code:
```Ext.Number.snap(3, 10, 0, 100); // => 0
Ext.Number.snap(13, 10, 0, 100); // => 10
Ext.Number.snap(17, 10, 0, 100); // => 20
Ext.Number.snap(21, 10, 0, 100); // => 20```
This example is simply rounding to the nearest 10, constrained between 0 and 100.

4. Thank you very much! Very well explained!