Copy link to clipboard
Copied
I am using the slider tool to blur a set of numbers up from 0 to 2.9. Initially, I had the issue that the numbers entered had four decimal places (ex. 2.1253 ) I only needed one decimal place. I found this expression to round up.
Math.round(effect("Slider Control")("Slider"))
Unfortunatey, this shows no decimal places and I need to just show one decimal place but cannot find an expression online that is word for word the expression I need.
Basically I need to go to the tenth decimal place. so from 0 to 2.9, does anyone know the exact expression for this?
Copy link to clipboard
Copied
If you want 1 decimal in all situations, even if the number is an integer, use effect("Slider Control")("Slider").value.toFixed(1);
Otherwise:
x = effect("Slider Control")("Slider");
Math.round(10*x)/10;
Xavier.
Copy link to clipboard
Copied
HI
This gives me 1 decimal place which is great, was finding that hard, but not "40.0" so the "%" sign I have on the end moves around.
Maybe .valuetoFixed is deprecated in newer CC versions?
Or maybe I am just stupid!
Copy link to clipboard
Copied
You need to append the string and possibly build it manually. Something like this perhaps:
mSlider=effect("XYZ")("Slider");
mDigits=4;
mValue=mSlider.toString();
mString=mValue.toFixed(1);
mLength=mString.length;
if (mLength < mDigits)
{oString=mString+".0"}
else
{oString=mString}
[oString]
Mylenium
Copy link to clipboard
Copied
Head just exploded Scanners style...
Using Quba for now.
Copy link to clipboard
Copied
Alternatively, the counter iExpressions from the Source Text Bundle also offer easy and flexible formatting of numbers:
Counter Numbers Expression | mamoworld
Copy link to clipboard
Copied
Sorry, saw your question late.
In effect("Slider Control")("Slider").value.toFixed(1); there is a dot (.) between "value" and "toFixed",
ie it's not valuetoFixed(1) but .value.toFixed(1).
Xavier
Copy link to clipboard
Copied
Align your text box right - then the % will stay in the same place. The numbers to the left will continue to move though.
Copy link to clipboard
Copied
Er, exactly. Obviously i thought of that. Uber number is the best way, once you have added sliders to it and saved a preset.
Ultimately i guess the best thing is to use a separate text layer for each integer, scripted to show either tens, hundredths etc. That could be centrally aligned so not move. Might try on Monday just for kicks
Copy link to clipboard
Copied
I found an easy way to set this up.
In addition to the data sliders, I created a slider called "precision", which will have values like 1,2,3,...
This allows you to control the precision of data from mulitple sliders with top-level control
I use the pow() function to convert to powers of 10
precision= 1 rounds to 1 decimal place, precision= 2 rounds to 2 decimal places, etc
full expression:
x=Math.round(thisComp.layer("CONTROL_LAYER").effect("precision")("Slider"))
x=Math.pow(10,x)
Math.round(thisComp.layer("DATA_LAYER").effect("slider_name")("Slider")*x)/x
Copy link to clipboard
Copied
there is much easy way to do this: Math.round(effect("Slider Control")("Slider"))/10
Copy link to clipboard
Copied
If you use toFixed(2), you will always get 2 decimal places. toFixed(1) gives you one decimal place. That is an easier workflow than fiddling with Math.round().
Copy link to clipboard
Copied
Hi
Er n no kornbif, that is just a tiny part of this, already discussed.
So i finally did this the other day.
It is funny how nobody else either understood there was a problem, or offered the solution.
Now i can build counters with any font.
You need a seperate layer for each integer.
You need to pick which number in sequence it is, missing out decimal points.
It is the only way to keep the number still.
I'll see if i can share it when i go back to work.
Copy link to clipboard
Copied
the easiest expression I've found to do this is this:
effect("Slider Control")("Slider").value.toFixed(1)
the number at the end of the expression defines the number of decimal places.
Copy link to clipboard
Copied
Its great. Now the number will goes like this 7.8, 7.9, and 8.
How to make it to 8.0. Which iI need the "0".
Copy link to clipboard
Copied
USE uberNUmber!
really
it has all the options you would need.
(apart from keeping any font centred, see above!)
let's you set decimal place and leading zeros.
Copy link to clipboard
Copied
effect("Slider Control")("Slider").value.toFixed(1)
the number at the end of the expression defines the number of decimal places.
Copy link to clipboard
Copied
I know its an old thread but this worked for me, from a video by Nick Khoo: https://youtu.be/j3HftxMxbfs?si=kTD7r0rpxqxWBs7w
s = "" + (effect(1)(1)[0]).toFixed(1); s.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- This will only work if the point controller (or your language equivalent) is the first effect in the effects stack.