toFixed & toPrecision Method in After Effects

Today’s post is about toFixed & toPrecision Method in After Effects. So without any further ado let’s dive right in!

Alright, so we are in After Effects and for this example, I’m going to go inside of this UKRAMEDIA.COM text and I’m going to ALT+CLICK (OPT+CLICK on a Mac) on the stopwatch icon of my source text to create an expression.

Alt right click on the stopwatch icon in After Effects

Next, I’m going to define a variable inside of the white text box. I am going to say n, you’re going to be and then I’ll say time * 100.


N Variable Time times a hundred in After Effects

Then I’m going to add a dollar sign plus the value n.

“$” = n

If I let go, you can see how I have the dollar sign plus the value.

Dollar sign plus value in After Effects

There are a lot of numbers in here, so let’s format this number. Let’s talk about this. So how do I only keep the whole number with no decimals? That’s where toFixed comes in handy.

I am going to keep going and I am going to say .toFixed() and if I leave the toFixed() parentheses blank, it is going to give me the whole number.


“$” = n.toFixed()

toFixed whole number in After Effects

That’s exactly what I am after here but what if let’s say I wanted to keep the whole number plus one decimal. How do I make that happen? Let me show you!

So inside of the toFixed() parentheses I’m going to say 1.


“$” = n.toFixed(1)

And as you do that, it is going to add one decimal.

Add one inside of the toFixed parenthesis in After Effects

Now, what if let’s say I want to have three decimals? Easy! Just replace 1 with 3.

Three decimals in toFixed in After Effects

So you get the idea of how easy this is. Now, what if let’s say I have a border around my numbers and I wanted to keep my value fixed at certain numbers.

Numbers inside of a border in After Effects

I want to have a dollar sign plus 4 digits inside of the border. Right now it starts out with 4 digits but then it grows and because of that, it gets bigger and it kind of gets out of my fixed border. That’s a problem. How do I keep it restricted to only let’s say 4 digits the whole time so that way it stays inside of my fixed border? That is where the toPrecision() comes in handy.

So I am going to replace toFixed() with toPrecision() and inside of the toPrecision() parenthesis I am going to say 4 because we want to keep it to four digits.


“$” = n.toPrecision(4);

Four digital in After Effects toPrecision
As you can see, it is now giving us the dollar sign that we are adding plus 4 digits. So it doesn’t matter how big the number gets, it will always give me four digits.

I hope you found this post useful. If you would like to learn more about Expression and how it can speed up your workflow in After Effects, check out my Learn After Effects Expressions Course.

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.


Over 110,000 downloads & counting!

These 7 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!