need help with maths, scroll bar issue

So for a re-usable class with a scroll bar in it I have two integers, I have height, that's the vertical length of the scroll bar, and position, that's the position of the scrolly peggy peg.

so for now I just want to output the percentage on the console, so if the peg is half way down the bar then I want to put something like

output(h%(position*100));

and I get 50 for example, every time the peg is half way down the bar, no matter what the h is!

something like that, but its one of those mornings where I cant get my maths around my head



Last edited on
the formula for percentage is: (position * 100) / h

EDIT: the % operator is modulo
Last edited on
oh yeah almost works :) now I need to get that against the total text height in the buffer, can you help here too? been experimenting, just not surewhat I am doing
Last edited on
To get the text position the formula is this:

text_positon = text_height * percentage / 100

or

text_positon = text_height * position / h
yep :) like a dream, I made all the bits and decided to deal with the numbers later, popped in the maths and boom works, im annoyed I just get a headache when I have to think 2 moves ahead, could be all that lead shot I used to eat
Topic archived. No new replies allowed.