Copy link to clipboard
Copied
**Summary:**
Here is a summary of what we have tried so far to resolve the ".0" problem in After Effects:
- The problem is that when interpolating between values using expressions, whole numbers are not displayed with a trailing ".0", resulting in numbers like 401, 402 instead of 401.0, 402.0.
- The first attempt involved adding logic to the expression to check if a number is a whole number and adding ".0" accordingly. This did not work as expected.
- The second attempt involved adjusting the expression to simplify the logic and ensure consistency in rounding to one decimal place. This also did not work as expected.
- The third attempt involved incorporating `toFixed(1)` to ensure one decimal place on all the values, including the start and end values and the interpolated value. This also did not work as expected.
- The fourth attempt involved using `valueAtTime()` on the slider value, instead of just using the value property. This was supposed to ensure that the expression evaluates the slider value at each frame, and not just at the current time. This also did not work as expected.
**Detail:**
Our latest attempt focused on utilizing the `valueAtTime()` method to retrieve the slider value at each frame, aiming for consistent evaluation throughout the animation. Despite this refinement, the issue persisted, indicating a deeper challenge in ensuring consistent ".0" display for whole numbers.
Here is the code we employed for the fourth attempt:
```javascript
// Get the current slider value and round it to one decimal place
currentValue = comp("Channel Outlet EG").layer("Chainage").effect("Slider Control")("Slider").valueAtTime(time).toFixed(1);
// Check if there are keyframes
if (comp("Channel Outlet EG").layer("Chainage").effect("Slider Control")("Slider").numKeys > 0) {
// Get start and end values and round them to one decimal place
startValue = (+comp("Channel Outlet EG").layer("StartChainage").text.sourceText).toFixed(1);
endValue = (+comp("Channel Outlet EG").layer("EndChainage").text.sourceText).toFixed(1);
// Interpolate
interpolatedValue = linear(time, key(1).time, key(2).time, startValue, endValue);
// Always display 1 decimal place
+interpolatedValue.toFixed(1);
} else {
// Always display 1 decimal place
+currentValue.toFixed(1);
}
```
This code endeavors to address the issue by ensuring that all values, including the slider value and the interpolated value, are rounded to one decimal place. However, the result still did not meet our expectation of displaying whole numbers with ".0" as intended.
**Explanation:**
In our project titled "Channel Outlet EG," we aim to create a dynamic animation where a numerical value represents the progress or status of a particular element. The "Chainage" layer, controlled by the "Slider Control" effect, serves as the dynamic component that drives this animation.
The numbers displayed, such as 401, 402, represent the progress or position along a specified chainage or distance. It's crucial for these numbers to be displayed with a consistent format, including ".0" for whole numbers, to maintain clarity and precision in communication.
Please let me know if you need further clarification or assistance with this matter.
Copy link to clipboard
Copied
If you want whole numbers with a trailing single decimal place, and adding .value to a slider like this won't do it:
V = effect("Slider Control")("Slider").value;
V.toFixed(1)
Try this:
V = effect("Slider Control")("Slider");
Rnd = Math.round(V);
Rnd.toFixed(1)
I think all you forgot was to take the slider value.
Copy link to clipboard
Copied
You can't interpolate the results of toFixed() because toFixed() returns a string, not a number. You should instead only apply toFixed() to the result of your interpolation once you are ready to incorporate it into a string value, such as the final result of a sourceText expression.