Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
The "0" custom format specifier in C#
The “0” custom specifier is a zero placeholder.
If the value to be formatted has a digit in the position where the zero appears in the format string, the the digit is copied to the resultant string. However, if this doesn’t happen, then a zero appears.
Here is our double variable.
double d; d = 292;
Now, by setting the following, you can easily make zero appear in the format string.
d.ToString("00000")
Example
using System;
using System.Globalization;
class Demo {
static void Main() {
double d;
d = 292;
Console.WriteLine(d.ToString("00000"));
Console.WriteLine(String.Format("{0:00000}", d));
d = 3.5;
Console.WriteLine(d.ToString("0.00", CultureInfo.InvariantCulture));
}
}
Output
00292 00292 3.50
Advertisements
