以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]数值框“NumericComboBox”计算出现近似值?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=28817)

--  作者:红颜
--  发布时间:2013/2/19 19:48:00
--  [求助]数值框“NumericComboBox”计算出现近似值?

在TextChanged事件中写入代码如下:

 

Dim t1 As String = Forms("找零计算").Controls("NumericComboBox1").text
Dim t2 As String = Forms("找零计算").Controls("NumericComboBox2").text
Forms("找零计算").Controls("NumericComboBox3").text = val(t1) - val(t2)

 

 

如:

10.1-10=0.0999999999999996

当小数部分的值在0.4-0.7之间时,结果是正确的。

[此贴子已经被作者于2013-2-19 20:00:27编辑过]

--  作者:有点甜
--  发布时间:2013/2/19 20:11:00
--  

正常的,这样改一下:

 

Dim t1 As Double = Forms("找零计算").Controls("NumericComboBox1").vlue
Dim t2 As Double = Forms("找零计算").Controls("NumericComboBox2").Value
Forms("找零计算").Controls("NumericComboBox3").value = math.round(t1- t2,6)


--  作者:布莱克朱
--  发布时间:2013/2/19 20:58:00
--  
数值框呀  要Val干嘛
--  作者:红颜
--  发布时间:2013/2/19 22:29:00
--  [求助]数值框“NumericComboBox”计算出现近似值?
以下是引用有点甜在2013-2-19 20:11:00的发言:

正常的,这样改一下:

 

Dim t1 As Double = Forms("找零计算").Controls("NumericComboBox1").vlue
Dim t2 As Double = Forms("找零计算").Controls("NumericComboBox2").Value
Forms("找零计算").Controls("NumericComboBox3").value = math.round(t1- t2,6)

楼主的代码有问题,不管放在哪个事件中,都提示错误:

第一行代码,Controls("NumericComboBox1").vlue,应是Value,属于失误。

第三行代码,math.round(t1- t2,6),去掉math。

 

Dim t1 As Double = Forms("找零计算").Controls("NumericComboBox1").Value
Dim t2 As Double = Forms("找零计算").Controls("NumericComboBox2").Value
Forms("找零计算").Controls("NumericComboBox3").value = Round2(t1- t2,1)

 

还需继续测试。

[此贴子已经被作者于2013-2-19 22:51:33编辑过]

--  作者:程兴刚
--  发布时间:2013/2/19 23:32:00
--  

format()


--  作者:红颜
--  发布时间:2013/2/19 23:49:00
--  
以下是引用程兴刚在2013-2-19 23:32:00的发言:

format()

请教版主,如何format,如用format,代码如何写,放在哪里?

能TextChanged事件中吗?


--  作者:程兴刚
--  发布时间:2013/2/20 1:46:00
--  
Forms("找零计算").Controls("NumericComboBox3").value = format(t1- t2,"0.00")
--  作者:红颜
--  发布时间:2013/2/20 16:10:00
--  
多谢斑竹