以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  设置小数位数  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=80737)

--  作者:漂亮美眉vszh
--  发布时间:2016/1/30 20:39:00
--  设置小数位数
先求出某一行的最大小数位数,并将这一行的所有的数字行设置成最大的小数位数
1.求出某一行的最大小数位数,附给i
2.把某行某列的数值用ROUND,设转置位数,但怎么不动,没反映
If e.DataRow("规格标准") <> "汇总比率" Or e.DataRow("规格标准") <> "汇总" Then
    Dim i As Integer
 i = e.DataRow("实测值样品1").tostring().length - e.DataRow("实测值样品1").Tostring().lastindexof(".")-1
If e.DataRow("实测值样品2").tostring().length - e.DataRow("实测值样品2").Tostring().lastindexof(".")-1 > i Then
i = e.DataRow("实测值样品2").tostring().length - e.DataRow("实测值样品2").Tostring().lastindexof(".")-1
End If
If e.DataRow("实测值样品3").tostring().length - e.DataRow("实测值样品3").Tostring().lastindexof(".")-1 > i Then
i = e.DataRow("实测值样品3").tostring().length - e.DataRow("实测值样品3").Tostring().lastindexof(".")-1
End If
If e.DataRow("实测值样品4").tostring().length - e.DataRow("实测值样品4").Tostring().lastindexof(".")-1 > i Then
i = e.DataRow("实测值样品4").tostring().length - e.DataRow("实测值样品4").Tostring().lastindexof(".")-1
End If
If e.DataRow("实测值样品5").tostring().length - e.DataRow("实测值样品5").Tostring().lastindexof(".")-1 > i Then
i = e.DataRow("实测值样品5").tostring().length - e.DataRow("实测值样品5").Tostring().lastindexof(".")-1
End If
If e.DataRow("实测值样品6").tostring().length - e.DataRow("实测值样品6").Tostring().lastindexof(".")-1 > i Then
i = e.DataRow("实测值样品6").tostring().length - e.DataRow("实测值样品6").Tostring().lastindexof(".")-1
End If
MessageBox.Show(i)
If e.DataRow("实测值样品1") IsNot Nothing Then
e.DataRow("实测值样品1") = round2(e.DataRow("实测值样品1"),i)
End If
If e.DataRow("实测值样品2") IsNot Nothing Then
e.DataRow("实测值样品2") = round2(e.DataRow("实测值样品2"),i)
End If
If e.DataRow("实测值样品3") IsNot Nothing Then
e.DataRow("实测值样品3") = round2(e.DataRow("实测值样品3"),i)
End If
If e.DataRow("实测值样品4") IsNot Nothing Then
e.DataRow("实测值样品4") = round2(e.DataRow("实测值样品4"),i)
End If
If e.DataRow("实测值样品5") IsNot Nothing Then
e.DataRow("实测值样品5") = round2(e.DataRow("实测值样品5"),i)
End If
If e.DataRow("实测值样品6") IsNot Nothing Then
e.DataRow("实测值样品6") = round2(e.DataRow("实测值样品6"),i)
End If

End If
Tables("全检子表").Rows(1)("实测值样品2") = Math.Round(Tables("全检子表").Rows(1)("实测值样品2"),2)
MessageBox.Show(Tables("全检子表").Rows(1)("实测值样品2"))
3.在命令窗口执行了这句代码,同样也出不来
Tables("全检子表").Rows(1)("实测值样品2") = Math.Round(Tables("全检子表").Rows(1)("实测值样品2"),2)
MessageBox.Show(Tables("全检子表").Rows(1)("实测值样品2"))

--  作者:大红袍
--  发布时间:2016/1/31 9:56:00
--  

我这样测试没问题。

 

Dim str As String = "123.45678"
str = math.Round(val(str), 2)
msgbox(str)

 

如果还有问题,做个例子上来测试。


--  作者:漂亮美眉vszh
--  发布时间:2016/2/1 15:32:00
--  
老师们帮我看看这道题~~~
--  作者:大红袍
--  发布时间:2016/2/1 15:33:00
--  
测试没问题啊,你到底想问什么,上传例子测试。
--  作者:漂亮美眉vszh
--  发布时间:2016/2/1 16:05:00
--  
以下是引用大红袍在2016/2/1 15:33:00的发言:
测试没问题啊,你到底想问什么,上传例子测试。
1.在命令窗口执行了这句代码,同样也出不来
Tables("全检子表").Rows(1)("实测值样品2") = Math.Round(Tables("全检子表").Rows(1)("实测值样品2"),2)
MessageBox.Show(Tables("全检子表").Rows(1)("实测值样品2"))
执行不成功,

2.Dim str As String = "123.45678"
str = math.Round(val(str), 2)
msgbox(str)

同样的代码,这样就能成功,放表事件就不行了~~
 

--  作者:漂亮美眉vszh
--  发布时间:2016/2/1 16:06:00
--  
我的此列本来就是双精度列,所以没用VAL转换~~
--  作者:大红袍
--  发布时间:2016/2/1 16:07:00
--  

不 可 能,上传实例。