以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  【已解决】[求助]0.1进位如何用代码写出来?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=141578)

--  作者:zto001
--  发布时间:2019/10/5 13:13:00
--  【已解决】[求助]0.1进位如何用代码写出来?
[求助]0.1进位如何用代码写出来?
不足0.1进0.1,比如21.11进位后是21.2
0.1进位想了半天没想出来
[此贴子已经被作者于2019/10/5 15:54:07编辑过]

--  作者:WELOVEFOX
--  发布时间:2019/10/5 15:00:00
--  
变量:
Dim jw1, jw2 As Decimal \'高精度小数
jw1 = 2.11
jw2 = Math.Ceiling(jw1 * 10)/10
Output.Show(jw1)
Output.Show(jw2)

同理其它类通,表列:Datacolchanged表事件
If e.DataCol.Name = "第九列" Then
    If e.DataRow.IsNull("第九列") Then
        e.DataRow("第十列") = Nothing
    Else
        e.DataRow("第十列") = Math.Ceiling(e.DataRow("第九列") * 10)/10
        e.DataRow("第九列") = Math.Ceiling(e.DataRow("第九列") * 10)/10
    End If
End If


--  作者:zto001
--  发布时间:2019/10/5 15:08:00
--  
                    临时数 = Math.Floor((重量-整数)*10)
Val =Math.Floor(重量*10)/10
                    If (重量-整数)*10-临时数=0 Then
                        余数=Val-整数
                    Else
                        余数=Val-整数+0.1
                    End If
            End Select

我是这样写出来的
但奇怪的是有时候他会自动再进一位。比如
6.3
23.8
8.3
这些他算出来的是6.4
23.9
8.4
是不是双精位小数的问题?


--  作者:zto001
--  发布时间:2019/10/5 15:10:00
--  
这样写比我的简单多了