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 6380907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:41+00:00 2026-05-25T02:19:41+00:00

When I try the below code, I get the output 2 084 001 .

  • 0

When I try the below code, I get the output 2 084 001. What could be wrong here? Isn’t my format string supposed to override the current culture settings?

decimal v = 2084000.7621m;
System.Console.WriteLine(v.ToString("#,###,###"));
System.Console.ReadLine();

If I modify the code to use ToString("#,###,###", CultureInfo.InvariantCulture), I get the expected output, i.e. 2,084,001 but I cannot specify a format provider when I set the DataFormatString property on my data bound controls.

WARNING: When using an escaped literal group separator, as described below in the accepted and other answers, the literal character used is always output, even if it isn’t needed, e.g. applying the format string #\,###\,### to a value of 324 results in an output value of ,,324.

  • 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-05-25T02:19:42+00:00Added an answer on May 25, 2026 at 2:19 am

    As far as I understand the Custom Numeric Format Strings, the , symbol is to place the group separator into the formatting (and not to specify which character to use). To make it an explicit symbol, you need to use the escape character \.

    v.ToString(@"#\,###\,###")
    

    Which has the disadvantage that the format string depends on the size of the number. In this case, you always get two commas in the resulting string, even if the number is smaller or higher.

    To override the group separator, you need to specify your own NumberFormatInfo.

    Got this test working:

    decimal v = 2084000.7621m;
    
    // clone the InvariantCulture to avoid specifying everything from scratch
    var myNumberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
    myNumberFormat.NumberGroupSeparator = "@";
    myNumberFormat.NumberDecimalSeparator = "*";
    Assert.AreEqual("2@084@000*7621", v.ToString("#,###,###.####", myNumberFormat));
    

    It actually doesn’t matter where and how many group separators you put into the format string. You could also make it: "#,#.####" with the exact same result. (Thats the advantage of using the group separator character, in contrast to the first solution).

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

Sidebar

Related Questions

When I try to use the code below I get a duplicate variable error
When I try to set the z variable in the code below, I get
I get the following error when I try and execute the code down below.
hi i have the following code below, where i try to get all the
I am using below code to get the current time in specific format and
the code below gives compilation error when I try to create test t[2]; because
When writing the below my code locks up on GetResponse. Why? try { WebRequest
I’m getting system error when I try to compile the code below on Visual
When i try to read a JSON string like below it goes to endless
In the code below, I tried iterating over the JSON object string. However, I

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.