<p><a href="https://i.sstatic.net/78dmy.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/78dmy.gif" alt="screengrab" /></a></p>
<p>Here's the code:</p>
<pre><code>myval = effect(&quot;Slider Control&quot;)(&quot;Slider&quot;);
SourceText = (Math.round(myval * 10))/10 + &quot;x&quot;
</code></pre>
<p>It's a really non-intuitive thing, but multiplying the value by 10, then rounding it to the nearest whole number, then dividing by 10 gives you what you need.</p>
<p>Think of it as &quot;how many values after the decimal point do I want?&quot; and count the number of zeroes in the number used.</p>

CC BY-SA 4.0
2022-09-02T13:35:22.387Z
That is not intuitive at all! Thanks for explaining it to me :)
Apeiron_Sound
CC BY-SA 4.0
2022-09-02T11:42:22.543Z
2022-09-02T11:42:22.543Z
tomh
<p>I've created this slider and counter which works just fine going from <code>5x</code> down to the <code>W</code>:</p>
<p><a href="https://i.sstatic.net/BwDro.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BwDro.png" alt="current view" /></a></p>
<p>The problem is that I need to create a condition that when a number hits <code>.0</code> it becomes a whole number, so in this case below, it shouldn't be <code>5.0x</code> but <code>5x</code>:</p>
<p><a href="https://i.sstatic.net/ty5Yp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ty5Yp.png" alt="problem" /></a></p>
<p>Here is my current expression:</p>
<blockquote>
<p><code>effect(&quot;Slider Control&quot;)(&quot;Slider&quot;).value.toFixed(1) + &quot;x&quot;;</code></p>
</blockquote>

<after-effects><animation><after-effects-expressions>
If function: turn into whole number when decimal is .0
Apeiron_Sound
# If function: turn into whole number when decimal is .0

(Asked by: username_0 on 2022-09-02)

I've created this slider and counter which works just fine going from `5x` down to the `W`:

[![current view](https://i.sstatic.net/BwDro.png)](https://i.sstatic.net/BwDro.png)

The problem is that I need to create a condition that when a number hits `.0` it becomes a whole number, so in this case below, it shouldn't be `5.0x` but `5x`:

[![problem](https://i.sstatic.net/ty5Yp.png)](https://i.sstatic.net/ty5Yp.png)

Here is my current expression:

> `effect("Slider Control")("Slider").value.toFixed(1) + "x";`

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


---

## 1 answers

### Answer by username_1 on 2022-09-02. Score: 0 | Accepted answer

Here's the code:
myval = effect("Slider Control")("Slider");
SourceText = (Math.round(myval * 10))/10 + "x"

It's a really non-intuitive thing, but multiplying the value by 10, then rounding it to the nearest whole number, then dividing by 10 gives you what you need.
Think of it as "how many values after the decimal point do I want?" and count the number of zeroes in the number used.

> **Comments:**
> **username_0**: That is not intuitive at all! Thanks for explaining it to me :)  

---

