;, false).NumberFormat;
Int64 myInt = 12345;
private void SetLL_Click(object sender, EventArgs e)
{
GN.CurrencyDecimalDigits = 4;
MessageBox.Show(myInt.ToString("C", GN), "保留四位小数");
}
4.自定义货币值中的小数点
Code
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
Int64 myInt = 123456789;
private void button1_Click(object sender, EventArgs e)
{
GN.CurrencyDecimalSeparator = "contentquot;;
MessageBox.Show("定义前:" + myInt.ToString("C") + "\n" + "定义后:" + myInt.ToString("C", GN), "自定义小数点为$符");
}
5.自定义货币值中小数点左边每一组的位数
Code
System.Globalization.NumberFormatInfo CN = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
Int64 myInt = 123456789012345;
int[] mySizes1 = { 2, 3, 1 };
int[] mySizes2 = { 2, 3, 2 };
CN.CurrencyGroupSizes = mySizes1;
MessageBox.Show("定义前:" + myInt.ToString("C") + "\n" + "定义后:" + myInt.ToString("C", CN), "{ 2, 3, 1 }格式");
CN.CurrencyGroupSizes = mySizes2;
MessageBox.Show("定义前:" + myInt.ToString("C") + "\n" + "定义后:" + myInt.ToString("C", CN), "{ 2, 3, 2 }格式");
6.自定义货币值中小数点左边数字分组字符
Code
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
Int64 myInt = 123456789;
GN.CurrencyGroupSeparator = "、";
MessageBox.Show("定义前: " + myInt.ToString("C") + "\n" + "定义后: " + myInt.ToString("C", GN), "分组字符用、号");
7.自定义百分比符号
效果: 默认符号: 10,257,865.84%
自定义符号&: 10,257,865.84&
自定义符号*: 10,257,865.84*
自定义符号#: 10,257,865.84#
Code
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
double intPrecnt = 102578.6584;
string strPrecnt = null;
GN.PercentSymbol = "%";
strPrecnt += "默认符号: " + intPrecnt.ToString("p", GN);
GN.PercentSymbol = "&";
strPrecnt += "\n自定义符号&: " + intPrecnt.ToString("p", GN);
GN.PercentSymbol = "*";
strPrecnt += "\n自定义符号*: " + intPrecnt.ToString("p", GN);
GN.PercentSymbol = "#";
strPrecnt += "\n自定义符号#: " + intPrecnt.ToString("p", GN);
MessageBox.Show(strPrecnt, "设置效果", Messa
|