Forums › Adobe After Effects Expressions › Combining 2 Expressions
Tagged: Basic
-
Combining 2 Expressions
-
Patrick Schmid
February 6, 2023 at 11:40 pmHi,
im trying to combine those 2 Expressions…
can anybody help me out? 🙂
+ add a option for Decimals?
1st Expression for changing the font of the Text-Layer:
var fontArray=[
“BerninaSansOffc-Regular”,
“DTFlowTextV1.011-Regular”
]
v=Math.round(thisComp.layer(“Null 19”).effect(“Font CTRL”)(“Slider”))
style.setFont(fontArray[v]);
2nd Expression is a Counter with a Point Control because i need numbers greater then 1million:
num = Math.round(effect(“Point Control”)(“Point”)[0]);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g,”,”);
}
addCommas(num)
-
Dan Ebberts
February 7, 2023 at 1:19 amTry this:
num = Math.round(effect("Point Control")("Point")[0]);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
}
txt = addCommas(num);
var fontArray=[
"BerninaSansOffc-Regular",
"DTFlowTextV1.011-Regular"
];
v=Math.round(thisComp.layer("Null 19").effect("Font CTRL")("Slider"));
style.setFont(fontArray[v]).setText(txt); -
Filip Vandueren
February 7, 2023 at 2:18 pmInstead of the custom addCommas() method you can also use the built-in method:
num.toLocaleString('en-us');
and if you want decimals, don’t use Math.round() in the first line but:
num = effect("Point Control")("Point")[0];
txt = num.toLocaleString('en-us', {maximumFractionDigits: 2});This will limit it to max 2 decimal digits.
if you always want 2 decimals (123.00) then:
txt = num.toLocaleString('en-us', {minimumFractionDigits: 2, maximumFractionDigits: 2});
Log in to reply.