C# 6 how to format double using interpolated string?
I have used interpolated strings for messages containing string
variables like $"{EmployeeName}, {Department}"
. Now I want to use an interpolated string for showing a formatted double
.
Example
var aNumberAsString = aDoubleValue.ToString("0.####");
How can I write it as an interpolated string? Something like $"{aDoubleValue} ...."
You can specify a format string after an expression with a colon (:
):
var aNumberAsString = $"{aDoubleValue:0.####}";
A colon after the variable specifies a format,
Console.Write($"{aDoubleValue:0.####}");