C# .NET - how to format double value - Asked By anbu n on 09-Jan-12 05:11 AM

need to format the following value  
 2886178.80

to

 2,886,178.80

...........................................
i need to have comma separation & also with 2 decimal places

Suchit shah replied to anbu n on 09-Jan-12 05:23 AM
write this code to put commas

=FormatCurrency(Fields!YourFieldName.Value,2)
 

or you can use this format for currency

="#,##0.#;#,##0.#'-';0"

you should put it on Format property of your custom field ,


kalpana aparnathi replied to anbu n on 09-Jan-12 05:26 AM

hi,

decimald = 2886178.80M;

Response.Write(d.ToString("N"));

Refer%20:%20http://msdn.microsoft.com/en-us/library/dwhawy9k%28v=vs.71%29.aspxhttp://msdn.microsoft.com/en-us/library/dwhawy9k%28v=vs.71%29.aspx

http://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.71%29.aspx

smr replied to anbu n on 09-Jan-12 05:35 AM
hi

try this

double value;
  
    value = 1.2;
    Console.WriteLine(value.ToString("#.##", CultureInfo.InvariantCulture));
    // Displays 1.2
  
    value = 123;
    Console.WriteLine(value.ToString("#####"));
    // Displays 123
  
    value = 123456;
    Console.WriteLine(value.ToString("[##-##-##]"));    
     // Displays [12-34-56]
  
    value = 2886178.80;
    Console.WriteLine(value.ToString("#"));
    // Displays 2886178.80
    Console.WriteLine(value.ToString("#,###,###.##"));
    // Displays  2,886,178.80
Riley K replied to anbu n on 09-Jan-12 06:03 AM


If you want culture specific then you can try like this 


double d = 2886178.80;
 
     string str=   d.ToString("N",new CultureInfo("en-US"));
 
      Console.WriteLine(str);
        Console.ReadLine();

Regards
dipa ahuja replied to anbu n on 09-Jan-12 06:06 AM
double intValue = 2886178.80;
Response.Write(intValue.ToString("N1", System.Globalization.CultureInfo.InvariantCulture));