Skip to main content
Participant
October 20, 2015
Answered

Integers and decimals / Slider Control

  • October 20, 2015
  • 2 replies
  • 6306 views

I am trying to count up from 00.0 to 27.3, using where each number is made up of 2 digits and 1 decimal place - so for the single digit numbers, there will still be a 0 ahead of it (ex: 3 would be listed at 03.0 when counting up). I found the expression to keep 1 decimal point at all time, even for integers:

effect("Slider Control")("Slider").value.toFixed(1);

But can't figure out how to have the single digit numbers have a zero in front of them. Does anyone know how to do this?

This topic has been closed for replies.
Correct answer Dan Ebberts

This should work:

s = effect("Slider Control")("Slider").value.toFixed(0);

(s.length <  2 ? "0" : "") + s

Dan

2 replies

Mathias Moehl
Community Expert
Community Expert
October 20, 2015

Yes, Dan's solution should work.

Alternatively, you can use the Counter Numbers iExpression. It has both parameters to configure the number of decimal places and leading zeros:

counter_numbers_0.png

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
maxwithdax
Community Expert
Community Expert
December 20, 2018

$100 plugin.. yeah... naw.

Mathias Moehl
Community Expert
Community Expert
December 20, 2018

The source text bundle that contains those counter expressions costs $44.99 and contains 22 iExpressions. This is about $2 per iExpression.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Dan Ebberts
Community Expert
Community Expert
October 20, 2015

This should work:

s = effect("Slider Control")("Slider").value.toFixed(1);

(s.length < 4 ? "0" : "") + s

Dan

brandonb96942845
Inspiring
August 18, 2019

Apologies for coming in late to the party but I need to add a single leading zero to a counter (i.e. so it'll show "01" instead of just "1"), but without the decimal place. I have Dan's expression and it gets me the leading zero, but I can't seem to get rid of the decimal.

Can anyone help?

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
August 18, 2019

This should work:

s = effect("Slider Control")("Slider").value.toFixed(0);

(s.length <  2 ? "0" : "") + s

Dan