Converting Length of Widget to Percentage

Hi! Math is not my strong suit, searching these forums has given me the answer very often (very appreciated!) but this one I can’t find.

I have a slider that I would like to show the percentage as the user slides it along the track; my solution would be to have a formula that would convert the difference between the left side of the track and the handle location out of the (variable) length of the track into a percentage. Does this make sense, and if so, is it possible to do? Alternatively, is there an easier option that I’m not realizing?

Thank you!

Hi there! You can definitely calculate the percentage of a slider track as the user slides along it, and you will need to use a formula to do that. I have an example file attached that uses the slider widget from Axure’s “Sample UI Patterns” library, with a “Set Text” action added in that sets the text of the “Current Position” label to the value of the slider track’s length, using the formula:

[[ ( (This.x - Track.x) / ( (Track.width-This.width) / 100) ).toFixed(0) ]]

Here’s the example file: Slider Example.rp (49.1 KB) and you can preview it live here.

Hopefully that helps!

1 Like

Super helpful! Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.