C#中的美元金额 [英] Dollar Amounts in C#
本文介绍了C#中的美元金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我浏览了其他一些帖子,但似乎无济于事.因此,我想要得到的是一个代码,该代码读取当前余额,并在其前面加上短语,并带有一个美元金额.而不是打印美元符号,而是打印 {0:C}
.我是否错误地使用了 {0:C}
?
I looked through some other posts but nothing seemed to help. So what I'm trying to get is a code that reads out the current balance, with the phrase in front of it, with a dollar amount. Instead of printing the dollar sign its printing {0:C}
. Am I using {0:C}
incorrectly?
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
double TotalAmount;
TotalAmount = 300.7 + 75.60;
string YourBalance = "Your account currently contains this much money: {0:C} " + TotalAmount;
Console.WriteLine(YourBalance);
Console.ReadLine();
}
}
}
推荐答案
string YourBalance =
string.Format("Your account currently contains this much money: {0:C} ",TotalAmount);
或在C#6.0+中使用字符串插值
or using string interpolation with C# 6.0+
string YourBalance = $"Your account currently contains this much money: {TotalAmount:C} ";
这篇关于C#中的美元金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文