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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:29:52+00:00 2026-06-07T21:29:52+00:00

Consider a Decimal value: Decimal value = -1234567890.1234789012M; i want to convert this Decimal

  • 0

Consider a Decimal value:

Decimal value = -1234567890.1234789012M;

i want to convert this Decimal value to a string, and include “thousands separators”.

Note: i don’t want to include thousand’s separators, i want to include digit grouping. The difference is important for cultures that don’t group numbers into thousands, or don’t use commas to separate groups

Some example output with different standard formatting strings, on my computer, with my current locale:

value.ToString()        =  -1234567890..1234789012   (Implicit General)
value.ToString("g")     =  -1234567890..1234789012   (General)
value.ToString("d")     =          FormatException   (Decimal whole number)
value.ToString("e")     =         -1..234568e++009   (Scientific)
value.ToString("f")     =         -1234567890..123   (Fixed Point)
value.ToString("n")     =     -12,,3456,,7890..123   (Number with commas for thousands)
value.ToString("r")     =          FormatException   (Round trippable)
value.ToString("c")     =   -$$12,,3456,,7890..123   (Currency)
value.ToString("#,0.#") =     -12,,3456,,7890..1

What i want (depending on culture) is:

en-US      -1,234,567,890.1234789012
ca-ES      -1.234.567.890,1234789012
gsw-FR     -1 234 567 890,1234789012    (12/1/2012: fixed gws-FR to gsw-FR)
fr-CH      -1'234'567'890.1234789012
ar-DZ       1,234,567,890.1234789012-
prs-AF      1.234.567.890,1234789012-
ps-AF       1،234،567،890,1234789012-
as-IN     -1,23,45,67,890.1234789012
lo-LA      (1234567,890.1234789012)     (some debate if numbers should be "1,234,567,890")
qps-PLOC  12,,3456,,7890..1234789012

How can i convert a Decimal to a string, with digit groupings?


Update: Some more desired output, using my current culture of :

-1234567890M             -->   -12,,3456,,7890
-1234567890.1M           -->   -12,,3456,,7890..1
-1234567890.12M          -->   -12,,3456,,7890..12
-1234567890.123M         -->   -12,,3456,,7890..123
-1234567890.1234M        -->   -12,,3456,,7890..1234
-1234567890.12347M       -->   -12,,3456,,7890..12347
-1234567890.123478M      -->   -12,,3456,,7890..123478
-1234567890.1234789M     -->   -12,,3456,,7890..1234789
-1234567890.12347890M    -->   -12,,3456,,7890..1234789
-1234567890.123478901M   -->   -12,,3456,,7890..123478901
-1234567890.1234789012M  -->   -12,,3456,,7890..1234789012

Update: i tried peeking at how Decimal.ToString() manages to use the General format to show all the digits that it needs to show:

public override string ToString()
{
    return Number.FormatDecimal(this, null, NumberFormatInfo.CurrentInfo);
}

except that Number.FormatDecimal is hidden somewhere:

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern string FormatDecimal(decimal value, string format, NumberFormatInfo info);

So that’s a dead end.

  • 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-07T21:29:54+00:00Added an answer on June 7, 2026 at 9:29 pm

    You can specify a custom pattern (the pattern will appropriately resolve to the culture specific method of grouping and the appropriate grouping and decimal separator characters). A pattern can have positive, negative and zero sections. The positive pattern is always the same but the negative pattern depends on the culture and can be retrieved from the NumberFormatInfo’s NumberNegativePattern property. Since you want as much precision as possible, you need to fill out 28 digit placeholders after the decimal; the comma forces grouping.

        public static class DecimalFormatters
        {
            public static string ToStringNoTruncation(this Decimal n, IFormatProvider format)
            {
                NumberFormatInfo nfi = NumberFormatInfo.GetInstance(format);
                string[] numberNegativePatterns = {
                        "(#,0.############################)", //0:  (n)
                        "-#,0.############################",  //1:  -n
                        "- #,0.############################", //2:  - n
                        "#,0.############################-",  //3:  n-
                        "#,0.############################ -"};//4:  n -
                var pattern = "#,0.############################;" + numberNegativePatterns[nfi.NumberNegativePattern];
                return n.ToString(pattern, format);
            }
    
            public static string ToStringNoTruncation(this Decimal n)
            {
                return n.ToStringNoTruncation(CultureInfo.CurrentCulture);
            }
        }
    

    Sample output

    Locale    Output
    ========  ============================
    en-US     -1,234,567,890.1234789012
    ca-ES     -1.234.567.890,1234789012
    hr-HR     - 1.234.567.890,1234789012
    gsw-FR    -1 234 567 890,1234789012
    fr-CH     -1'234'567'890.1234789012
    ar-DZ     1,234,567,890.1234789012-
    prs-AF    1.234.567.890,1234789012-
    ps-AF     1،234،567،890,1234789012-
    as-IN     -1,23,45,67,890.1234789012
    lo-LA     (1234567,890.1234789012)
    qps-PLOC  -12,,3456,,7890..1234789012
    

    There is currently no locale that uses NegativeNumberFormat 4 (n -), so that case cannot be tested. But there’s no reason to think it would fail.

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

Sidebar

Related Questions

Consider this code: enum { ERR_START, ERR_CANNOTOPENFILE, ERR_CANNOTCONNECT, ERR_CANNOTCONNECTWITH, ERR_CANNOTGETHOSTNAME, ERR_CANNOTSEND, }; char* ERR_MESSAGE[]
consider that i have a migration as follows create_table :dummies do |t| t.decimal :the_dummy_number
Consider this code: var query = db.Table .Where(t => SomeCondition(t)) .AsEnumerable(); int recordCount =
Consider this: NSString *whatever=[NSString stringWithFormat:@My float: %.2f,aFloat]; This will round my aFloat to 2
Consider the need for a function in C# that will test whether a string
Consider the following code: namespace ConsoleApplication1 { class Program { static void Main(string[] args)
Consider this code segment Class.forName (oracle.jdbc.OracleDriver); connection = DriverManager.getConnection (jdbc:oracle:thin:@//XXX.XXX.XXX.XXX:1521/xe, abc, def); DatabaseMetaData metaData=connection.getMetaData();
Consider this example, it shows two possible ways of lazy initialization. Except for being
I have a BigDecimal value and I want to know if the number of
Consider: CREATE PROCEDURE LowerCityDiscounts @city VARCHAR(45), @decrease DECIMAL(10,2) AS BEGIN BEGIN TRANSACTION; UPDATE Customers

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.