以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 累加多个单精度小数后,结果值无小数 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=95512) |
-- 作者:luobo_ljl -- 发布时间:2017/1/22 13:22:00 -- 累加多个单精度小数后,结果值无小数 请问老师,累加多个单精度小数后,结果值无小数是怎么回事呢? |
-- 作者:有点色 -- 发布时间:2017/1/22 13:25:00 -- 如果是列,你试试改成双精度或者高精度。
如果你写的是代码,看看你是不是赋值给整数了。 |
-- 作者:luobo_ljl -- 发布时间:2017/1/22 14:34:00 -- Dim nx1 As Integer = Tables("库存报表").Rows.Count Dim nx2 As Integer Dim nx3 As Single Dim nx4 As Single Dim nx5 As Single Dim nx6 As Single For nx2 = 0 To nx1-1 Dim rx As Row = t3.Rows(nx2) nx3 = nx3 + rx("期初金额") nx4 = nx4 + rx("入库金额") nx5 = nx5 + rx("出库金额") nx6 = nx6 + rx("结存金额") Next |
-- 作者:foxor -- 发布时间:2017/1/22 15:23:00 -- 没有定义t3 |
-- 作者:luobo_ljl -- 发布时间:2017/1/22 15:27:00 -- Dim t1 As Table = Tables("自购物项基础数据表") Dim t2 As Table = Tables("自购物项基础数据表.出库") Dim t3 As Table = Tables("库存报表") Dim n1 As Integer = t1.Rows.Count Dim n2 As Integer For n2 = 0 To n1-1 Tables("自购物项基础数据表").Position = n2 Dim r1 As Row = t1.Current t3.AddNew Dim r3 As Row = t3.Current r3("物项代码") = r1("物项代码") r3("物项名称") = r1("物项名称") r3("规格型号") = r1("规格型号及其他参数") r3("材质") = r1("材质或牌号") r3("炉批号") = r1("炉批号或产品编号") r3("单位") = r1("单位ZW") r3("单价") = r1("单价") r3("结存数量") = r1("账面结存数量") r3("结存金额") = r1("账面余额") Dim rq1 As Date = r1("正式入库日期") Dim rq11 As Integer = rq1.Month Dim rq12 As Integer = rq1.Year Dim rq2 As Date = Date.Now Dim rq21 As Integer = rq2.Month Dim rq22 As Integer = rq2.Year If rq11 = rq21 And rq12 = rq22 Then r3("期初数量") = 0 r3("期初金额") = 0 r3("入库数量") = r1("数量ZW") r3("入库金额") = r1("金额") Dim n4 As Integer = t2.Rows.Count Dim n41 As Integer Dim n42 As Double Dim n43 As Single If n4>0 Then For n41 = 0 To n4-1 Dim r2 As Row = t2.Rows(n41) n42 = n42 + r2("出库数量") n43 = n43 + r2("金额") Next r3("出库数量") = n42 r3("出库金额") = n43 Else r3("出库数量") = 0 r3("出库金额") = 0 End If Else Dim n3 As Integer = t2.Rows.Count Dim n31 As Integer Dim n32 As Double Dim n321 As Double Dim n33 As Single Dim n331 As Single If n3>0 Then For n31 = 0 To n3-1 Dim r2 As Row = t2.Rows(n31) Dim rq3 As Date = r2("出库日期") Dim rq31 As Integer = rq3.Month Dim rq32 As Integer = rq3.Year Dim rq4 As Date = Date.Now Dim rq41 As Integer = rq4.Month Dim rq42 As Integer = rq4.Year If rq31 = rq41 And rq32 = rq42 Then n32 = n32 + r2("出库数量") n33 = n33 + r2("金额") End If Next r3("期初数量") = r1("账面结存数量") + n32 r3("期初金额") = r1("账面余额") + n33 r3("入库数量") = 0 r3("入库金额") = 0 r3("出库数量") = n32 r3("出库金额") = n33 Else r3("期初数量") = r1("账面结存数量") r3("期初金额") = r1("账面余额") r3("入库数量") = 0 r3("入库金额") = 0 r3("出库数量") = 0 r3("出库金额") = 0 End If End If Next Dim nx As Integer = 1 For Each dr As Row In Tables("库存报表").Rows dr("序号")=nx nx=nx+1 Next Dim nx1 As Integer = Tables("库存报表").Rows.Count Dim nx2 As Integer Dim nx3 As Single Dim nx4 As Single Dim nx5 As Single Dim nx6 As Single For nx2 = 0 To nx1-1 Dim rx As Row = t3.Rows(nx2) nx3 = nx3 + rx("期初金额") nx4 = nx4 + rx("入库金额") nx5 = nx5 + rx("出库金额") nx6 = nx6 + rx("结存金额") Next Tables("库存报表").AddNew Dim rx1 As Row = t3.Current rx1("期初金额") = nx3 rx1("入库金额") = nx4 rx1("出库金额") = nx5 rx1("结存金额") = nx6 rx1("炉批号") = "合计" |
-- 作者:luobo_ljl -- 发布时间:2017/1/22 15:28:00 -- 一开始就定义了 |
-- 作者:有点色 -- 发布时间:2017/1/22 18:19:00 -- 试试定义成这样
Dim nx3 As Double = 0 |