Numeric and Date Format Specifiers
Control how numbers and dates render.
Standard Numeric Formats
Format specifiers are short codes that shape how numbers display. Common ones are N, C, P, F, and D.
using System;
class Program {
static void Main() {
double n = 1234.5;
Console.WriteLine($"{n:N2}");
}
}Number Format: N
N2 formats a number with thousands separators and two decimal places.
using System;
class Program {
static void Main() {
Console.WriteLine($"{1234567.891:N2}");
}
}All lessons in this course
- String Interpolation Basics
- Composite Formatting with string.Format
- Numeric and Date Format Specifiers
- Raw String Literals