Need good calculation to get right index by x from width

44 Views Asked by At

enter image description here

Here, I made a canvas app with total width is (742px), so here what I need, I just want to calculate and get right section (Index) by X only.

Example, I got 393.9015504531791 as X calculated with whole width, So X here it's 0.5x in real, how do I would calculate that and get right Index between (1-17) only through X? enter image description here

I tried many calcs I know, but honestly I'm not good on Math lol.

1

There are 1 best solutions below

0
MBo On BEST ANSWER
OneWidth = 542 / 17
LeftEdge = (742 - 542) / 2
Index = Math.floor((X - LeftEdge) / OneWidth) + 1