Activity › Forums › Adobe After Effects Expressions › Text layer looking at slider with an addition and keeping to two decimal places
-
Text layer looking at slider with an addition and keeping to two decimal places
Posted by Ashley Aslett on September 17, 2021 at 8:21 pmHi,
I have a text layer looking at a slider control, I want to add 2 to the number that it is looking at. I guess something like this:
thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)+2
However I want to keep the resulting number to 2 decimal places, I know you can use the following but not sure where to add this into the above expression as keep getting errors?
.value.toFixed(2)
Any help greatly appreciated!
Ashley Aslett replied 4 years, 9 months ago 3 Members · 9 Replies -
9 Replies
-
Dan Ebberts
September 17, 2021 at 8:27 pmSomething like this should work:
(thisComp.layer("% P&L").effect("Slider Control")("Slider")+2).toFixed(2) -
Fabrice Leconte
September 17, 2021 at 8:28 pmHello,
Try something like this:
(thisComp.layer('% P&L').effect('Slider Control')('Slider')+2).toFixed(2);
-
Ashley Aslett
September 17, 2021 at 8:30 pmDan you are an absolute hero, saved my bacon again!
Fabrice thanks also for the super swift reply.
Sending huge thanks both your ways!
-
Ashley Aslett
September 17, 2021 at 8:58 pmLast one, I promise!!
Can either of you help with the below:
“$”+ num = (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
}
addCommas(num)
Basically I have a text layer looking at a slider, multiplying that number by 10,000,000, keeping it to two decimal places and adding in commas….however I want a dollar sign at the start.
Searching around I came up with the above but the $ symbol is not showing.
As always your help is appreciated.
-
Ashley Aslett
September 17, 2021 at 9:03 pmAll good chaps, just figured it out by switching it around!…
num = “$”+ (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
}
addCommas(num)
-
Fabrice Leconte
September 17, 2021 at 10:44 pmYes or you can use Intl.NumberFormat
Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0
}).format((thisComp.layer('% P&L').effect('Slider Control')(1) * 10000000));
-
Ashley Aslett
October 13, 2021 at 3:14 pmHey guys, one more question on the above!
When inputting the following number on the below script -0.1742331 the output is $-1,742,331. Is there a way to change the script so the output is -$1,742,331…the minus symbol comes before the dollar sign rather than after it?
num = “$”+ (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
}
addCommas(num)
As always any help would be super appreciated!
-
Dan Ebberts
October 13, 2021 at 7:18 pmTry it this way:
n = thisComp.layer("% P&L").effect("Slider Control")("Slider");
sign = n < 0 ? "-" : "";
num = sign + "$"+ (Math.abs(n)*10000000).toFixed(0);
function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
addCommas(num)
-
Ashley Aslett
October 17, 2021 at 3:06 pmAs always, worked perfectly!
Your help is super appreciated! Thanks
Reply to this Discussion! Login or Sign Up