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

How do you display $ dollar signs and % signs?

Community Beginner ,
May 17, 2022 May 17, 2022

I'm creating a calculator but I cannot display a $ before the number unless there is a space. We've tried various Javascripts but it's becoming more work than it is worth. What are some tips and formatting options?

393
Translate
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
People's Champ ,
May 18, 2022 May 18, 2022

Are you talking about displaying it in a text entry?

Translate
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 ,
May 20, 2022 May 20, 2022

Yes. So I can't write $$$var_somedollarvalue$$.

Translate
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
People's Champ ,
May 23, 2022 May 23, 2022

In JavaScript you just need to append the amount you want to display with the dollar sign.

 

window.var_somedollarvalue = "$"+window.var_amount;

 

I created a variable called var_amount, which is the number that is calculated.

 

Your test caption would just be: $$var_somedollarvalue$$

Translate
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 ,
Sep 26, 2022 Sep 26, 2022

Thank you! Because there was additional funky math before it, I had to truncate all the additional digits using this:
window.cpAPIInterface.setVariableValue("var_truncDollar", "$"+var_vacationTotalx.toLocaleString('en-US', {maximumFractionDigits:2}));

Translate
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
Contributor ,
Sep 28, 2022 Sep 28, 2022
LATEST

Just curious, why did you decided to use the .toLocaleString...method for your number adjustment? Hope you are having a great day!

Translate
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
Resources
Help resources