Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:33:05+00:00 2026-06-04T11:33:05+00:00

I have an object MyObject that contains a property MyProp that is sometimes numeric.

  • 0

I have an object MyObject that contains a property MyProp that is sometimes numeric. At the moment, I’m showing the number as text like this:

$('#MyDiv').text(MyObject.MyProp);

I want to add formatting to this number. I can check it’s numeric but I’m wondering how to do the number formatting.

if ($.isNumeric(MyObject.MyProp) === false) {

   $('#MyDiv').text(MyObject.MyProp);

} else {

   var PrettyNumber = MakePrettyNumber(MyObject.MyProp);
   $('#MyDiv').text(PrettyNumber);
}

I’m thinking about looping through the length of the number string and adding commas to separate thousands and add a dot for decimal. Is there a better way? One that doesn’t require a plug-in?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:33:06+00:00Added an answer on June 4, 2026 at 11:33 am
    function MakePrettyNumber(x) {
      var res = x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      res = res.replace(/^([^\.]*)$/g, "$1.000");
      return res;
    }
    

    See here for details: How to print a number with commas as thousands separators in JavaScript

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a serialized object MyObject that contains integer foo. I set a value
I have an object graph that contains objects that are (for purposes of this
I have an object model MyObject that contains a nullable byte as one of
In C#, suppose you have an object (say, myObject ) that is an instance
This is what my object looks like (I don't have a lot of control
I have an object model that contains a boolean MyBool and I have a
I have an object that contains the date of an event. In the database,
I have an object which contains several different NSStrings. When displaying this object, depending
I have an object that implements IteratorAggregate and ArrayAccess , which internally contains an
I have a business object that can be edited via PropertyGrid. It contains list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.