You must Sign In to post a response.
  • Category: ASP.NET

    How to conver a number to comma separated number

    Hi to all

    i have a number 123456. i get this value from database and display that.. when i display the value like that 1,23,456... where i do that in backend or front end... explain the methods




    Thanks in Regards
    ----------------------
    Saravana Perumal.N
  • #664830
    Hai Saravana,
    If you just want to display it then its better to do the formatting at the front-end.
    As this is the number so you might have the data type as int at the back-end.
    So I would suggest you to format it to the front end so that it will display to the user in the required format and whenever they change anything, again you need to save it to the number by formatting this to the number.
    Hope it will help you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #664832
    Hello Saravana,
    if you want to display the fetched value as comma separated format then just use below code to fetch it as comma separated with sql query.

    SELECT substring(CAST(CONVERT(varchar, CAST(123456 AS money), 1) AS varchar),1,len(CAST(CONVERT(varchar, CAST(123456 AS money), 1) AS varchar))-3)


    Thank you.

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo
    http://www.dotnetsquare.com
    Blog: http://blog.msahoo.net

  • #664833
    Try below the code :


    double dblValue = -12445.6789;
    Console.WriteLine(dblValue.ToString("N", CultureInfo.InvariantCulture));
    // Displays -12,445.68
    Console.WriteLine(dblValue.ToString("N1",
    CultureInfo.CreateSpecificCulture("sv-SE")));
    // Displays -12 445,7

    int intValue = 123456789;
    Console.WriteLine(intValue.ToString("N1", CultureInfo.InvariantCulture));
    // Displays 123,456,789.0


    ---
    decimal value = 123.456m;
    Console.WriteLine(value.ToString("C2"));
    // Displays $123.46

    decimal value = 123.456m;
    Console.WriteLine("Your account balance is {0:C2}.", value);
    // Displays "Your account balance is $123.46."


    double value = 12345.6789;
    Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));

    Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));

    Console.WriteLine(value.ToString("C3",
    CultureInfo.CreateSpecificCulture("da-DK")));
    // The example displays the following output on a system whose
    // current culture is English (United States):
    // $12,345.68
    // $12,345.679
    // kr 12.345,679

    int value;

    value = 12345;
    Console.WriteLine(value.ToString("D"));
    // Displays 12345
    Console.WriteLine(value.ToString("D8"));
    // Displays 00012345

    value = -12345;
    Console.WriteLine(value.ToString("D"));
    // Displays -12345
    Console.WriteLine(value.ToString("D8"));
    // Displays -00012345

    double value = 12345.6789;
    Console.WriteLine(value.ToString("E", CultureInfo.InvariantCulture));
    // Displays 1.234568E+004

    Console.WriteLine(value.ToString("E10", CultureInfo.InvariantCulture));
    // Displays 1.2345678900E+004

    Console.WriteLine(value.ToString("e4", CultureInfo.InvariantCulture));
    // Displays 1.2346e+004

    Console.WriteLine(value.ToString("E",
    CultureInfo.CreateSpecificCulture("fr-FR")));
    // Displays 1,234568E+004

    int integerNumber;
    integerNumber = 17843;
    Console.WriteLine(integerNumber.ToString("F",
    CultureInfo.InvariantCulture));
    // Displays 17843.00

    integerNumber = -29541;
    Console.WriteLine(integerNumber.ToString("F3",
    CultureInfo.InvariantCulture));
    // Displays -29541.000

    double doubleNumber;
    doubleNumber = 18934.1879;
    Console.WriteLine(doubleNumber.ToString("F", CultureInfo.InvariantCulture));
    // Displays 18934.19

    Console.WriteLine(doubleNumber.ToString("F0", CultureInfo.InvariantCulture));
    // Displays 18934

    doubleNumber = -1898300.1987;
    Console.WriteLine(doubleNumber.ToString("F1", CultureInfo.InvariantCulture));
    // Displays -1898300.2

    Console.WriteLine(doubleNumber.ToString("F3",
    CultureInfo.CreateSpecificCulture("es-ES")));
    // Displays -1898300,199

  • #664875
    Use this code

    int money = 21232221;
    var output = money.ToString("N0");


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.