-2

I have value in 133354.4 format but I want this as 133, 354.40 format only.

I don't know how to convert this using c#?

Thanks in advance.

Dexters
  • 2,419
  • 6
  • 37
  • 57
  • look here. http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number – zdd Mar 20 '14 at 02:10
  • @user3432842.. look at globalization format i have given below – Dexters Mar 20 '14 at 02:33
  • Do you need comma *and* space? If yes you'll need to build custom CultureInfo for that as I don't think there is one with `", "` as separator. – Alexei Levenkov Mar 20 '14 at 02:33
  • Side note: please update title to something that explain what you need. "help me with this" is not very helpful for future readers. And check [this](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts) about thank you notes. – Alexei Levenkov Mar 20 '14 at 02:35

2 Answers2

3

you need to use customized formatting (More) which is available in Globalization

using System.IO;
using System;
using System.Globalization;

class Program
{
    static void Main()
    {
        double value = 133354.4;
        Console.WriteLine(value.ToString("#,#.00", CultureInfo.InvariantCulture));

    }
}

output:

133,354.40

Dexters
  • 2,419
  • 6
  • 37
  • 57
0

First, convert it to decimal, for sample:

string number = "133354.4";

decimal value = decimal.Parse(number);

string formatedNumber = value.ToString("N");

ToString(string format) method from decimal type, has a format type you can specify the type of number you want to print. Look at the documentation and add the specific type you need.

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194