0Pricing
C# Academy · Lesson

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

  1. String Interpolation Basics
  2. Composite Formatting with string.Format
  3. Numeric and Date Format Specifiers
  4. Raw String Literals
← Back to C# Academy