Skip to main content
Participant
Jan 29, 2022 10:45 AM UTC
Answered

After Effects Expression for replacing dots with commas

Hello all.

 

I have the following expression for my source code: 

effect("Einstellungen für Schieberegler")("Schieberegler").value.toFixed(1)+" %";

 

Unfortunately, the digits after the comma are separated by a dot. Since I work in Germany, I would like to have the place after the comma separated by a comma. 

 

Unfortunately, this does not work as an addition:

replace (".",",");

 

Can anyone help me?

 

Thank you very much!

OussK
OussKCorrect answer
Community Expert
Jan 29, 2022 3:05 PM UTC

Also this one is better if you want to automatically add comma for every 3 digits 

 

 

num = effect("Slider Control")("Slider").value.toFixed(1).toString().replace(".", ",")+"%";
function addCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
addCommas(num)

 

 

 

num =effect("Einstellungen für Schieberegler")("Schieberegler").value.toFixed(1).toString().replace(".", ",")+" %";
function addCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
addCommas(num)

 

 

 

 

12 replies

Roland Kahlenberg
Legend
Apr 10, 2025 11:11 AM UTC

You'll want to use toLocaleString() to solve such issues related to international numbering systems. 

I've started writing a series of short tutorials on using Modern Javascript in After Effects Expressions. These are part of my Advanced Course on Developing Advanced Intelligent Design Assets - these are start of the moment AE Templates/MoGRTs. 

https://www.broadcastgems.com/post/modern-javascript-adobe-after-effects-expressions-tolocalestring

I'll add more topics in the days and weeks ahead. Quite a few will also make it into my upcoming AE Script, AeXpressions NotePad - I hope it's OK to share this teaser/snippet. 






 

Translate
Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
OussK
Community Expert
Community Expert
Jan 29, 2022 2:51 PM UTC

try this 

effect("Slider Control")("Slider").value.toFixed(1).toString().replace(".", ",")+"%";

in German

effect("Einstellungen für Schieberegler")("Schieberegler").value.toFixed(1).toString().replace(".", ",")+" %";

 

Translate
OussK
Community Expert
OussKCommunity ExpertCorrect answer
Community Expert
Jan 29, 2022 3:05 PM UTC

Also this one is better if you want to automatically add comma for every 3 digits 

 

 

num = effect("Slider Control")("Slider").value.toFixed(1).toString().replace(".", ",")+"%";
function addCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
addCommas(num)

 

 

 

num =effect("Einstellungen für Schieberegler")("Schieberegler").value.toFixed(1).toString().replace(".", ",")+" %";
function addCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
addCommas(num)

 

 

 

 

Translate
ShiveringCactus
Community Expert
Community Expert
Jan 29, 2022 2:43 PM UTC

Make sure your project's expression engine is Javascript (which you can do in File > Project Settings > Expressions, then use this expression:

text.sourceText.split('.').join(',');

 

Someone who knows Javascript better than me can explain why what you would usually use:

text.sourceText.replace(/./g, ",")

replaces all the characters and there's probably a simple character addition to tell the script to only select '.' and not take it to mean all characters.

 

Translate
Participant
Jan 30, 2022 8:49 AM UTC

Dear ShiveringCactus
Thank you very much for your help. Unfortunately it doesn't work, although I checked before that my file uses Java script (thanks for the tip). The result was that the whole number was replaced by the word "numbers".
However, OussK's idea worked:
effect("Slider settings")("Slider").value.toFixed(1).toString().replace(".", ",")+" %";

Translate
yahyabirinci
Participant
Dec 14, 2023 12:25 PM UTC

Thank you very much, this code worked for me too.

 

Translate