C#6如何使用插值字符串格式化double?

C#6如何使用插值字符串格式化double?,c#,double,string-interpolation,c#-6.0,C#,Double,String Interpolation,C# 6.0,我对包含string变量的消息使用了插值字符串,如$“{EmployeeName},{Department}”。现在我想使用插值字符串来显示格式化的double 范例 var aNumberAsString = aDoubleValue.ToString("0.####"); 如何将其写入插值字符串?类似于$“{aDoubleValue}…”“您可以在带有冒号的表达式后面指定格式字符串(:): 变量后的冒号指定格式 Console.Write($"{aDoubleValue

我对包含
string
变量的消息使用了插值字符串,如
$“{EmployeeName},{Department}”
。现在我想使用插值字符串来显示格式化的
double

范例

var aNumberAsString = aDoubleValue.ToString("0.####");

如何将其写入插值字符串?类似于
$“{aDoubleValue}…”“

您可以在带有冒号的表达式后面指定格式字符串(
):


变量后的冒号指定格式

Console.Write($"{aDoubleValue:0.####}");

可以找到可能的格式规范列表,注意:字符串插值使用当前区域性。对于不敏感的插值,可以使用System.FormattableString:
Invariant($”at{num}”)
中的不变量。看见
Console.Write($"{aDoubleValue:0.####}");