Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String format for Double in C#
Use the static method String.Format for form double string format in C#.
For three decimal places −
String.Format("{0:0.000}", 987.383);
String.Format("{0:0.000}", 987.38);
String.Format("{0:0.000}", 987.7899);
For thousands separator −
String.Format("{0:0,0.0}", 54567.46);
String.Format("{0:0,0}", 54567.46);
To format string −
Example
using System;
class Demo {
public static void Main(String[] args) {
Console.WriteLine("Three decimal places...");
Console.WriteLine( String.Format("{0:0.000}", 987.383));
Console.WriteLine( String.Format("{0:0.000}", 987.38));
Console.WriteLine(String.Format("{0:0.000}", 987.7899));
Console.WriteLine("Thousands Separator...");
Console.WriteLine(String.Format("{0:0,0.0}", 54567.46));
Console.WriteLine(String.Format("{0:0,0}", 54567.46));
}
}Advertisements