
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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)); } }
- Related Articles
- Format double type in Java
- String format for DateTime in C#
- How to convert a double value into a Java String using format method?
- Format double with new DecimalFormat("0.#####E0") in Java
- Explain double column cash book and its format
- How to Convert Double to String to Double in Java?
- Convert double to string in Java
- Convert String to Double in Java
- Convert double value to string in Java
- Convert string (varchar) to double in MySQL
- Precision String Format Specifier In Swift
- Java String format() method example.
- How to format date string in PowerShell?
- How to format JSON string in JavaScript?
- Java Program to convert Double into String using toString() method of Double class

Advertisements