将值四舍五入至最接近的50的倍数

编程入门 行业动态 更新时间:2024-10-13 08:23:40
本文介绍了将值四舍五入至最接近的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的倍数

本文发布于:2023-11-07 23:32:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:倍数   最接近   四舍五入

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!