-
c#如何自定义百分比值中的小数位数
此属性用于获取或设置在百分比值中使用的小数位数。
其语法格式为:
publicintPercentDecimalDigits{get;set;}
属性值:-在百分比值中使用的小数位数。默认值为2。
主要代码如下:
privatevoidbutton1_Click(objectsender,EventArgse)
{
System.Globalization.NumberFormatInfoGN=newSystem.Globalization.CultureInfo("zh-CN",false).NumberFormat;
DoublemyInt=0.9774;
stringstrInfo=null;
GN.PercentDecimalDigits=1;
strInfo+="保留一位小数:"+string.Format(myInt.ToString("P",GN));
GN.PercentDecimalDigits=2;
strInfo+="n保留二位小数:"+string.Format(myInt.ToString("P",GN));
GN.PercentDecimalDigits=4;
strInfo+="n保留四位小数:"+string.Format(myInt.ToString("P",GN));
GN.PercentDecimalDigits=6;
strInfo+="n保留六位小数:"+string.Format(myInt.ToString("P",GN));
MessageBox.Show(strInfo,"定义效果");
}