本文介绍了如何更改/转换除法或乘法的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
—SA
This all is so wrong so I don''t know how to write about it. This short fragment shows that you tend to invite disasters. Just stop it.
You need a habit to perform arithmetic calculations with numeric types, never with texts. You need to declare all numeric variables explicitly, then convert you UI texts to the numeric values, perform calculations and finally populate UI with the result of calculations. All the numeric variables I mentioned above should be in one separate class or structure. All three steps should be three separate methods: 1) UI to data, 2) calculations with data, 3) data to UI.
Now, your question itself is completely unclear. If you think that you need to round value 200.1247 to 200.12, think again. Rounded is never needed, well, almost never. If you need to present rounded values in UI, this is completely different thing which does not require rounding operation itself. You just need to call ToString or string.Format with appropriate format specifiers. If you avoid explicit rounding, it can guarantee you that a rounded value cannot sneak into calculations and cause loss of precision.
—SA
如何更改/转换除法或乘法的结果 除法的示例= 200.1247变为200.12 我使用此编码 请更正我的代码是
How do I change / convert the result of the division or multiplication examples of the division = 200.1247 becomes 200.12 I use this coding Please also corrected my code is
Private Sub Cover() Const Konstan As Single = 1000 WG1.Text = Val(QP1.Text) * Val(BM1.Text) TW1.Text = (Val(WG1.Text) + Val(WG6.Text) + Val(WG11.Text)) GI1.Text = (Val(WG1.Text) / Val(TW1.Text)) * Val(QL1.Text) * Konstan 'Cover L WG6.Text = Val(QP2.Text) * Val(BM6.Text) GI6.Text = (Val(WG6.Text) / Val(TW1.Text)) * Val(QL1.Text) * Konstan 'Cover R WG11.Text = Val(QP3.Text) * Val(BM11.Text) GI11.Text = (Val(WG11.Text) / Val(TW1.Text)) * Val(QL1.Text) * Konstan End Sub推荐答案
这一切都是错的,所以我不知道该怎么写.这个简短的片段说明您倾向于引发灾难.停止吧. 您需要养成使用数值类型而不是文本执行算术计算的习惯.您需要明确声明所有数字变量,然后将您的UI文本转换为数字值,执行计算,最后使用计算结果填充UI.我上面提到的所有数字变量都应在一个单独的类或结构中.所有这三个步骤应为三种单独的方法:1)从UI到数据,2)使用数据进行计算,3)从数据到UI. 现在,您的问题本身还不清楚.如果您认为需要将200.1247的值四舍五入为200.12,请再考虑一下.四舍五入是不需要的,嗯,几乎不需要.如果您需要在UI中显示舍入值,则这是完全不同的事情,它本身不需要舍入操作.您只需要使用适当的格式说明符来调用ToString或string.Format.如果避免显式舍入,则可以保证舍入后的值不会潜入计算并导致精度损失.
更多推荐
如何更改/转换除法或乘法的结果
发布评论