private decimal balance;
public void PayIn(decimal amount)
{
balance += amount;
}
public bool PayOut(decimal amount)
{
if (balance > amount)
{
balance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足");
return false;
}
}
public decimal Balance
{
get
{
return balance;
} }
public override string ToString()
{
return string.Format("save:Balance={0,6:c}", balance);
{0,6:c}应该是控制字符串的输出格式吧,0.6:c是什么意思,是固定的吗
}
public void PayIn(decimal amount)
{
balance += amount;
}
public bool PayOut(decimal amount)
{
if (balance > amount)
{
balance -= amount;
return true;
}
else
{
Console.WriteLine("余额不足");
return false;
}
}
public decimal Balance
{
get
{
return balance;
} }
public override string ToString()
{
return string.Format("save:Balance={0,6:c}", balance);
{0,6:c}应该是控制字符串的输出格式吧,0.6:c是什么意思,是固定的吗
}
字母 含义
C或c Currency 货币格式
D或d Decimal 十进制格式(十进制整数,不要和.Net的Decimal数据类型混淆了)
E或e Exponent 指数格式
F或f Fixed point 固定精度格式
G或g General 常用格式
N或n 用逗号分割千位的数字,比如1234将会被变成1,234
P或p Percentage 百分符号格式
R或r Round-trip 圆整(只用于浮点数)保证一个数字被转化成字符串以后可以再被转回成同样的数字
X或x Hex 16进制格式
string str=string.Format("{0,30:d}{1,10:c}{2,6:c}{3,15:c}",1234,12,1,10);的输出是这样的
1234 ¥12.00 ¥1.00 ¥10.00
http://www.cnblogs.com/cn795/archive/2010/08/12/1798307.html