C#中四舍五入的问题?
答案:2 悬赏:0 手机版
解决时间 2021-11-17 13:01
- 提问者网友:感性作祟
- 2021-11-16 13:36
C#中四舍五入的问题?
最佳答案
- 五星知识达人网友:長槍戰八方
- 2021-11-16 13:59
double txtnum = Convert.ToDouble(this.textBox1.Text);
if (txtnum < 0)
{
txtnum = Math.Round(txtnum + 5 / Math.Pow(10, 3), 2, MidpointRounding.AwayFromZero);
}
else
{
txtnum = Math.Round(Convert.ToDouble(txtnum), 2, MidpointRounding.AwayFromZero);
}
MessageBox.Show(txtnum.ToString());
if (txtnum < 0)
{
txtnum = Math.Round(txtnum + 5 / Math.Pow(10, 3), 2, MidpointRounding.AwayFromZero);
}
else
{
txtnum = Math.Round(Convert.ToDouble(txtnum), 2, MidpointRounding.AwayFromZero);
}
MessageBox.Show(txtnum.ToString());
全部回答
- 1楼网友:深街酒徒
- 2021-11-16 15:04
private double GetSiSheWuRuNumber(double d, int pointBits)
{
return Math.Round(d, pointBits,MidpointRounding.AwayFromZero);
}
使用:double dd = GetSiSheWuRuNumber(12.553, 2);
结果 dd=12.55
{
return Math.Round(d, pointBits,MidpointRounding.AwayFromZero);
}
使用:double dd = GetSiSheWuRuNumber(12.553, 2);
结果 dd=12.55
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯