4 Different Ways to Round Numbers in After Effects

In this post, I will show you 4 different ways to round numbers in After Effects.

First, I am going to ALT+Click on the Source Text stopwatch icon of the Ukramedia.com text layer.

Click on the stopwatch icon in After Effects

Next, I will give it a variable t. I am going to say t, you are going to equal to time * 20. Then I will say t in the new line like so:

t = time*20;
t

Rounded numbers in After Effects

As you can see from the screenshot above, right now we have number 12.6793450126793. How do we run this up to 13? Let me show you 4 options.

Option 1: toFixed()

The first option is the one we have gone over before. It is called toFixed.

In this example, I am going to add to the t variable below t = time*20;.

I am going to say t.toFixed() and when I do that, you can see that it did round it up to 13.

t = time*20;
t.toFixed()

toFixed in After Effects
The cool thing about toFixed() is that you can actually hold on to some decimals inside of the parenthesis. For example,  we can type 2 inside toFixed(2) and it is going to give us 2 decimals like so:

Two decimals in After Effects

If you type 4, then it is going to give you 4 decimals.

Four decimals in After Effects

Option #2: Math.round()

The second method is probably the most common. It is called Math.round().

All you do is just type Math.round() and inside the parentheses, we are going to add t and that will round it up.

t = time*20;
Math.round(t)

Math Round in After Effects

Now the third and fourth methods are a bit more specific. let me show you what I am talking about.

I am going to go back to the beginning. I am going to type t in the second line so we can see our numbers again.

t = time*20;
t

rounding up numbers in after effects

In some cases, you want to round numbers down. For example, right now I have the number 12.6793460126793.

Rounding Numbers down or upwards in After Effects

What if I wanted to round this number downwards? We cannot use toFixed() and Math.round() methods because those two will round everything up for us instead.

So how do I round downwards? In other words, I want the number to be 12. all the time until we change a number.

Option #3: Math.floor()

So to round this number downwards, we will use Math.floor() and inside the parenthesis, I am going to type t.

t = time*20;
Math.floor(t);

Math Floor in After Effects Rounding numbers Downwards

As you can see, right now it went down to 12 instead of 13. Now how do I do the opposite? How do I always round upwards? For example, I am going type t in the second line like so:

t = time*20;
t

Rounded upwards in After Effects

This number right now normally would be rounded to 28, but how do I round it upwards? In other words, every time I
change this to a number, I want it to go upwards.

Option #4: Math.ceil()

We are going to use the ceiling method instead of the floor.

So I am going to say Math.ceil() and inside the parenthesis, I am going to put our variable t. Now watch what happens.

t = time*20;
Math.ceil(t)

Math ceiling method in After Effects

And just like that, it rounded upwards, which is exactly what I wanted.

I hope you found this tip useful. I have created a course that goes deeper into the world of After Effects Expressions. Check it out!

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!