Copy link to clipboard
Copied
I have an expression that is working in animating a percentage based on a slider control.
n=thisComp.layer("Null 1").effect("Pie Slice 2")("Slider")
nRound=Math.round(n*10)/10;
check = nRound % 1
if (check == 0){
"" + nRound + ".0" + "%"
}else{
nRound
}
What I can't figure out is why the "%" only appears when the number is whole and not there constantly? After reading through Dan Ebbert page, he indicates that you can in fact add it (which I thought I did correctly) but only on the whole numbers. When it's animating through the "tenths" the % does not appear.
I'm sure it's something simple, but I can't figure it out.
Thanks for your help.
In your if/else statement you are only adding the % in the cases where it is a whole number. You would need to change it to:
if (check == 0){
"" + nRound + ".0" + "%";
} else {
"" + nRound + "%";
}
Also, here's an alternative way to write the expression:
n=thisComp.layer("Null 1").effect("Pie Slice 2")("Slider");
n.value.toFixed(1) + "%";
Copy link to clipboard
Copied
In your if/else statement you are only adding the % in the cases where it is a whole number. You would need to change it to:
if (check == 0){
"" + nRound + ".0" + "%";
} else {
"" + nRound + "%";
}
Also, here's an alternative way to write the expression:
n=thisComp.layer("Null 1").effect("Pie Slice 2")("Slider");
n.value.toFixed(1) + "%";
Copy link to clipboard
Copied
Awesome, thanks so much.
I also found out that if you take the "check" out all together and write it like this:
n=thisComp.layer("Null 1").effect("Pie Slice 2")("Slider")
nRound=Math.round(n*10)/10;
"" + nRound + ".0" + "%"
Several ways it seems. Actually, now I'm curious. Does the check need to be in there at all? What is the logic behind it and the way you wrote it as well?
Thanks again!
Copy link to clipboard
Copied
It looks like you were rounding it down to one decimal place, then checking if it was a whole number, and if so you were needing to add ".0" to the end as it wouldn't be there otherwise.
The two line alternative expression I gave was complete and didn't need the check. I bypassed all that by using .toFixed(1) which sets any numbers to one decimal place.