本文介绍了将值四舍五入至最接近的50的倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数字四舍五入到最接近的50的倍数 例如:如果 数是34 结果0 或 人数= 76 结果50 或 数= 345 结果300 或 number = 365 结果350 或 编号= 5678 结果5650 或 人数= 5635 结果5600 像这样,我想通过单击calcButton
I want to round a number to its nearest multiple of 50 Eg:if the number is 34 result 0 or number=76 result 50 or number=345 result 300 or number=365 result 350 or number=5678 result 5650 or number=5635 result 5600 Like this,I wanna round of a value of txtbox1 by clicking calcButton
推荐答案Well,如果将34舍入为最接近的50的倍数,那么就舍入为txtbox1的值,而不是0. 但是,如果您想按照示例中的建议进行四舍五入-只需除以50,然后再使用整数再乘以50.容易吧? Well, if you round 34 to the nearest multiple of 50, you''d get 50, not 0. But if you want to round down as suggested by your examples - just divide by 50, then multiply by 50 again using integers. Easy huh?
protected void Button1_Click(object sender, EventArgs e) { if ((int.Parse(TextBox1.Text) / 50) * 50 < int.Parse(TextBox1.Text)) { TextBox1.Text=(int.Parse(TextBox1.Text) / 50 * 50).ToString(); } }
检查以下线程以获取选项和示例: stackoverflow/questions/326476/vba-how-to-round-to-nearest-5-or-10-or-x [ ^ ] stackoverflow/questions/1531695/round-to-nearest-five-c [^ ] check the following threads for options and examples: stackoverflow/questions/326476/vba-how-to-round-to-nearest-5-or-10-or-x[^] stackoverflow/questions/1531695/round-to-nearest-five-c[^]
更多推荐
将值四舍五入至最接近的50的倍数
发布评论