We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
I would like to split the number returned by a slider into individual digits to animate other things with it.
E.g. reading out the 4th digit of the slider number, 302534 returns the 4th digit = 2 or the 6th digit which is 3. Or in otherwords is there an expression to get the value of a specific digit position in a number that consists of several digits…Thank you
Something like this maybe:
s = effect("Slider Control")("Slider"); digit = 4; Math.floor(s/Math.pow(10,digit-1))%10
Thank you Dan for your expertise and quick reply. Your code perfectly solved my problem. I used it to manipulate video footage of a counter on a laboratory display. I cut out the digits from 0-9 and with your expression and time-remap I was able to control the counter of the filmed display. Thank you.
You can also try converting that number from the slider into a string. You can then access a character of that string by index and convert it back to a number. Something like this:
var sliderValue = effect("Slider Control")("Slider"); var asString = String(sliderValue) // .replace(/\D/g,''); var result = +asString; result;
In the square brackets you can type the index of the character. The + sign converts it back to a number.
Note that this will include non numbers (if your slider is a decimal like 200.5 the "." will be part of the string, at index 3). You can uncomment the "replace" method and this will clean your string of any character that isn't a number.
Thank you Saaroz for your expertise and quick reply.
By far the simplest way to set the number of decimal points is to use toFixed().
will always give 2 decimal places like this: 0.00 or 1.03
will always give 1 decimal place like this: 10.2 or 24039.9
That's all there is to it. I use toFixed all the time.
Once you set the number of decimal places you can use
sliderValue = effect("Slider Control")("Slider").value.toFixed(3); asString = String(sliderValue) // .replace(/\D/g,''); result = + asString; result;
But beware that the number in brackets counts the digits from the left so 234.573 would return 5. but 34.573 would return the 7. That's the only problem with converting to a string. I don't know how to count from the right.
The Math.Floor solution counts from the right.
Thank you Rick for your expertise and quick reply.
Probably as simple as a
with the first number being the digit to return and the second merely saying to only return one character. If you're sure it's just numbers you don't need any other checks, though more regex-savvy people would probably give you a much longer example.
Thank you Mylenium for your expertise and quick reply.