Thursday, January 26, 2012

Digits after decimal point in c#.net

This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.

Ex :-
.ToString("N");         // 98.5864256544   ==>   98.58
or
String.Format("{0:0.00}", 123.4567);      // "123.46"
 
Double myDouble = 1234567890;
String myString = myDouble.ToString( "(###) ### - ####" );
// The value of myString is "(123) 456 – 7890".
 
Double myDouble = 123.4567890;
String myString = myDouble.ToString( ".###" );
// The value of myString is "123.456". 
 
 
string[] specifiers = { "C", "E", "e", "F", "G", "N", "P", 
                        "R", "#,000.000", "0.###E-000",
                        "000,000,000,000.00###" }; 

No comments:

Post a Comment