• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

After Effects Expression for replacing dots with commas

Community Beginner ,
Jan 29, 2022 Jan 29, 2022

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

4.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 29, 2022 Jan 29, 2022

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
...

Votes

Translate

Translate
Community Expert ,
Jan 29, 2022 Jan 29, 2022

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2022 Jan 30, 2022

Copy link to clipboard

Copied

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(".", ",")+" %";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 15, 2023 Dec 15, 2023

Copy link to clipboard

Copied

LATEST

In regex syntax the "." symbol is a special character that matches any character other than a line terminator. It should work if you escape it:

 

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


If you are trying to get a better handle on how regular expressions work an online regex tester like the one at https://regex101.com can be invaluable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2022 Jan 29, 2022

Copy link to clipboard

Copied

try this 

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

in German

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2022 Jan 29, 2022

Copy link to clipboard

Copied

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)

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2022 Jan 30, 2022

Copy link to clipboard

Copied

Dear OussK

You are my hero. Thank you very much! I wish you a sunny Sunday 😉

Kind regards from Düsseldorf (Germany),
Stefan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2022 Feb 11, 2022

Copy link to clipboard

Copied

you're welcome, don't forget mark the answer as correct if it help you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

Dear OussK

You are also my hero, thank you very much from Phnom Penh!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 20, 2023 Nov 20, 2023

Copy link to clipboard

Copied

The '.toString' thing saved me man, thanks a million!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines