| **Math.round: show always a number of 2 digits**
by Davide Mitidieri on Nov 7, 2016 at 10:12:33 pm |

Hi,

I'm using the expression

`Math.round(effect(("Slider Control")("Slider")))`

in the source of a text layer, which contains a slider. I need to show always 2 digits of the integer number in the slider; for example, "5" sould be shown as "05", while "10" should be shown as "10".

How can I modify the expression in order to do this?

Thanks in advice.

| **Re: Math.round: show always a number of 2 digits** by Cassius Marques on Nov 8, 2016 at 11:50:14 am |

`x=Math.round(effect("Slider Control")("Slider")).toFixed(0);`

while (x.length < 2) x = "0" + x; x

It adds a 0 if the length of the string is smaller than 2, otherwise its just the number.

Cassius Marques

http://www.zapfilmes.com | **Re: Math.round: show always a number of 2 digits** by Davide Mitidieri on Nov 8, 2016 at 8:23:24 pm |

Ok it works, thanks a lot!

However, what if I'm working with a string made of 2 numbers, separated by ":"? (I'm making a chronometer)

I've tried to edit your expression, but it seems a bit harder, and I'm not used to work with After Effects expressions.

Thanks in advice

| **Re: Math.round: show always a number of 2 digits** by stephen dixon on Nov 9, 2016 at 1:37:40 am |

use Cassius's expression for each group of numbers, and then join them together by simply adding them. So say you have two sliders, one for seconds and one for minutes (is that what you're doing?):

`sec = Math.round(effect("Slider Control")("Slider")).toFixed(0);`

while (sec.length < 2) sec = "0" + sec;

min= Math.round(effect("Slider Control")("Slider 2")).toFixed(0);

while (min.length < 2) min = "0" + min;

min + ":" + sec

Stephen Dixon

Editor, Animator, Motionographer

Museum Victoria