string a = "123.123456789";
string b = "123";
double aa = 123.123456789;
//方法一:通过截取字符串来实现 截取
string[] arr = b.Split('.');
if (arr.Length>1)//防止超出索引
{
if (arr[1].Length > 2)
{
arr[1] = arr[1].Substring(0, 2);
b = arr[0] + "." + arr[1];
}
}
//方法二: 直接通过vs自带的方法:round 四舍五入
//double c = Math.Round(aa, 3);
string c = b;
Response.Write(c);
string b = "123";
double aa = 123.123456789;
//方法一:通过截取字符串来实现 截取
string[] arr = b.Split('.');
if (arr.Length>1)//防止超出索引
{
if (arr[1].Length > 2)
{
arr[1] = arr[1].Substring(0, 2);
b = arr[0] + "." + arr[1];
}
}
//方法二: 直接通过vs自带的方法:round 四舍五入
//double c = Math.Round(aa, 3);
string c = b;
Response.Write(c);