Results 1 to 5 of 5

Thread: [RESOLVED] Comma Formatting of number with leading Zeros removed

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    415

    Resolved [RESOLVED] Comma Formatting of number with leading Zeros removed

    I currently have a number that I want to display with comma's between the thousands. I have found in the documentation that I can format it using ToString("0,000,000")

    if the number is 7654321, it correctly displays it as 7,654,321

    However if the Number is just 4321, it display it as 0,004,321

    Looking at the documentation, I can't find a formatting option to remove the leading zero's so that 4321 would be displayed as 4,321.

    Without testing the length of the string and specifying a format depending upon the string length, is there a formatting option that removes the leading Zeros' ?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,836

    Re: Comma Formatting of number with leading Zeros removed

    ToString("#, ##0") should do the trick

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    415

    Re: Comma Formatting of number with leading Zeros removed

    That's Great Thanks. Works Perfectly.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,949

    Re: [RESOLVED] Comma Formatting of number with leading Zeros removed

    Try...

    Code:
    Dim number as decimal = 123456.00
    MsgBox(number.ToString("n0")) ' = "123,456"
    If you need 2 decimal places...

    Code:
    Dim number as decimal = 123456.789
    MsgBox(number.ToString("n2")) ' = "123,456.79"
    Last edited by .paul.; Feb 13th, 2025 at 07:30 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    415

    Re: [RESOLVED] Comma Formatting of number with leading Zeros removed

    Excellent, thanks .Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width