Menu
Coddy logo textTech

Formatted Output

Part of the Fundamentals section of Coddy's C# journey — lesson 40 of 69.

challenge icon

Challenge

Beginner

Modify the output so that it will always print a double value with two decimal places.

In C#, you can use Console.WriteLine with string interpolation or string.Format to achieve this formatting.

int num = 0;
Console.WriteLine($"number: {num:F2}");

Or with string.Format:

int num = 0;
Console.WriteLine(string.Format("number: {0:F2}", num));

Try it yourself

using System;

public class Program {
    public static void Main(string[] args) {
        
    }
}

All lessons in Fundamentals