String Format for Float

Posted by Akiii under C# category on | Points: 40 | Views : 1843
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 off.

String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 125.8); // "125.80"
String.Format("{0:0.00}", 12345.0); // "12345.00"

Thanks and Regards

Comments or Responses

Login to post response