10 September 2011

How To Format String to Double

String format for double
 
// just two decimal places
 String.Format("{0:0.00}", 123.4567);      // "123.46"
 
// max. two decimal places 
 String.Format("{0:0.##}", 123.4567);      // "123.46" 

// Digits before decimal point 
String.Format("{0:00.0}", 123.4567);      // "123.5"
 
// thousand separator 
String.Format("{0:0,0.0}", 12345.67);     // "12,345.7" 

// Align numbers with Spaces
String.Format("{0,10:0.0}", 123.4567);    // "     123.5"
String.Format("{0,-10:0.0}", 123.4567);   // "123.5     "
String.Format("{0,10:0.0}", -123.4567);   // "    -123.5"
String.Format("{0,-10:0.0}", -123.4567);  // "-123.5    "
 
//  Align numbers with spaces
String.Format("{0:0.00;minus 0.00;zero}", 123.4567);   // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567);  // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0);        // "zero"
String.Format("{0:my number is 0.0}", 12.3);   // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3);          // "12aaa.bbb3"
 


thank you to csharp-examples.net
takken from : http://www.csharp-examples.net/string-format-double/

No comments:

Post a Comment

Twiit.. Twiit... Gulp