通过System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;来设置格式,保留位数,比如:
保留一位小数:75.2%
保留二位小数:75.16%
保留四位小数:75.1600%
保留六位小数:75.160000%
只需要设置 PercentDecimalDigits 属性即可.
下面看一段源码:
System.Globalization.NumberFormatInfo GN = new System.Globalization.CultureInfo("zh-CN", false).NumberFormat;
Double myInt = 0.7516;
string strInfo = null;
GN.PercentDecimalDigits = 1;
strInfo += "保留一位小数:" + string.Format(myInt.ToString("P", GN));
效果如下: