Formatted Output
Part of the Fundamentals section of Coddy's C# journey — lesson 40 of 69.
Challenge
BeginnerModify 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3