<p>Normally I would use Math.round like this when trying to display text:</p>
<pre><code>slider = (effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value);
tidying = (Math.round(slider * 100))/100;
SourceText = &quot;$&quot; + tidying + &quot;bn&quot; +&quot;\r&quot; +&quot;DEBTS&quot;;
</code></pre>
<p>the .value is sometimes needed to force AE to look at the slider as a number, not as an object.</p>
<p>tidying is being done to round (up) to 2 decimal places
\r gives a line break</p>
<p>text is appended with +”text”+</p>
<p>If you want to round down, you can use</p>
<pre><code>Math.floor()
</code></pre>
<p>instead</p>

CC BY-SA 4.0
2022-01-31T07:12:42.750Z
I came up with this hacky way to round down but it's not as clean as Math.floor() so replaced - thanks!    

`num= 2903.99302;     fix= num.toFixed(0);     len= fix.length;     str= num.toString();     new = str.substr(0,len);     result= parseInt(new);`
AutoBaker
CC BY-SA 4.0
2022-01-29T13:40:19.813Z
2022-01-29T13:40:19.813Z
tomh
<p>Thought this would be simple but doesn't seem so.  How can I remove all numbers after the decimal point in an expression, or round down to 0 decimal places (which is the same result)</p>
<p>For instance I have an integer: <code>2903.99302</code>
I want to remove everything after decimal place, so that it results in <code>2903</code></p>
<p>Can't find how to do this.  Some ideas:</p>
<pre><code>num = 2903.99302;
dec = num.search(&quot;.&quot;);  // OR dec = num.find(&quot;.&quot;);

result = num.substr(0, dec);
</code></pre>
<p>or</p>
<pre><code>num = 2903.99302;
result = num.rounddown(0);
</code></pre>
<p>or</p>
<pre><code>num = 2903.99302;
result = num.toFixed(0);
</code></pre>
<p>Apparently AE can also use JavaScript in recent versions.  I'm on version 2021 and it's not basic javascript functions aren't recognised so not sure if there's some weird syntax...</p>

<after-effects><after-effects-expressions>
After effects expression how to round DOWN or remove numbers after decimal point
AutoBaker
# After effects expression how to round DOWN or remove numbers after decimal point

(Asked by: username_0 on 2022-01-28)

Thought this would be simple but doesn't seem so.  How can I remove all numbers after the decimal point in an expression, or round down to 0 decimal places (which is the same result)
For instance I have an integer: 2903.99302
I want to remove everything after decimal place, so that it results in 2903
Can't find how to do this.  Some ideas:
num = 2903.99302;
dec = num.search(".");  // OR dec = num.find(".");

result = num.substr(0, dec);

or
num = 2903.99302;
result = num.rounddown(0);

or
num = 2903.99302;
result = num.toFixed(0);

Apparently AE can also use JavaScript in recent versions.  I'm on version 2021 and it's not basic javascript functions aren't recognised so not sure if there's some weird syntax...

**Tags:** after-effects, after-effects-expressions


---

## 1 answers

### Answer by username_1 on 2022-01-29. Score: 1 | Accepted answer

Normally I would use Math.round like this when trying to display text:
slider = (effect("Slider Control")("Slider").value);
tidying = (Math.round(slider * 100))/100;
SourceText = "$" + tidying + "bn" +"\r" +"DEBTS";

the .value is sometimes needed to force AE to look at the slider as a number, not as an object.
tidying is being done to round (up) to 2 decimal places
\r gives a line break
text is appended with +”text”+
If you want to round down, you can use
Math.floor()

instead

> **Comments:**
> **username_0**: I came up with this hacky way to round down but it's not as clean as Math.floor() so replaced - thanks!      `num= 2903.99302;     fix= num.toFixed(0);     len= fix.length;     str= num.toString();     new = str.substr(0,len);     result= parseInt(new);`  

---

