日期:2014-05-18  浏览次数:20896 次

怎么将long a = 1.676767676 变为1.67
如题

------解决方案--------------------
long a = 1.676767676
string temp = a.ToString();
temp = temp.subString(0, 4);
a = long.Parse(temp);

------解决方案--------------------
first, a 的值将是 1,你要知道 long 不可能有小数部分...

next, 你可以用decimal...

last, 格式化...
------解决方案--------------------
math.Round(intVariable,2)
------解决方案--------------------
double a = 1.676767;
int i = (int)(a * 100);
a = (double)i / 100;
textBox1.Text = a.ToString();
------解决方案--------------------
a=Math.Round(a,2);
//另 long 是整的吧