Add comma separator for numbers in the Counter Widgets

Is there anyway to format the Counter Widgets so they show commas in the numbers such as 5,000 instead of 5000?

Comments

  • We already answered on your question but we`ll re-paste this answer here as well :)

    "Sorry but this is not possible. Counter works on math and is not able to count when have different symbols then only numbers."
  • If there anyway to format the outputted text at all? Seems like this would be useful to be able to have this as when you deal with larger numbers, it would be easier for viewers to read. Can you point me in the direction of the file where the calculations happen? I would like to see if there is someway to accomplish this.

    -AJ
  • In comments section on TF we sent you info inside which files you can have a look. If you will see, you understand this is standard math and there is nothing what you can do with that.
  • You could add an option in the element configuration to "apply english formatting". Your counter/animation loop that iterates the number through the determined range could be filtered through code below that alters the output of the numbers before writing it to the html element containing it. The math would not be adversely affected because it's processing some original range of numbers to animate from X to Y, but you'd just apply the user-specified number format. The user would still need to enter like 2 and 180000 as the range, and you'd take care of the commas on the output.

    If you can access the numbers from the animation loop in PHP, you'd use:

    // english notation (default)
    $english_format_number = number_format($number);
    // 1,235
    

    If you must access them in javascript, you'd use:

    const number = 1234567.89;
    
    // Using default formatting (based on users locale)
    const formattedNumberDefault = number.toLocaleString();
    console.log(formattedNumberDefault); // Output depends on user's locale
    
    // Specifying a specific locale (e.g., en-US)
    const formattedNumberUS = number.toLocaleString('en-US');
    console.log(formattedNumberUS); // Output: "1,234,567.89"
    
    // Specifying options for formatting
    const options = {
      style: 'decimal',  // Other options: 'currency', 'percent', etc.
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    };
    const formattedWithOptions = number.toLocaleString('en-US', options);
    console.log(formattedWithOptions); // Output: "1,234,567.89"
    


  • Hi @haveabyte,

    Thank you for your message.

    We have this topic on our feature request list, and we will surely take this into account.


    Best regards

  • Hi there is it possible to also add a "." as thousands separator?

    Thank you!

Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.