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?
I tried many calcs I know, but honestly I'm not good on Math lol.
CodePudding user response:
OneWidth = 542 / 17
LeftEdge = (742 - 542) / 2
Index = Math.floor((X - LeftEdge) / OneWidth) 1