将值四舍五入至最接近的50的倍数 [英] Round value to its nearest multiple of 50

查看:167
本文介绍了将值四舍五入至最接近的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();
       }
   }


检查以下线程以获取选项和示例:

http://stackoverflow.com/questions/326476/vba-how-to-round-to-nearest-5-or-10-or-x [ http://stackoverflow.com/questions/1531695/round-to-nearest-five-c [^ ]
check the following threads for options and examples:

http://stackoverflow.com/questions/326476/vba-how-to-round-to-nearest-5-or-10-or-x[^]

http://stackoverflow.com/questions/1531695/round-to-nearest-five-c[^]


这篇关于将值四舍五入至最接近的50的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆