Foxtable(狐表)用户栏目专家坐堂 → 累加多个单精度小数后,结果值无小数


  共有2054人关注过本帖树形打印复制链接

主题:累加多个单精度小数后,结果值无小数

帅哥哟,离线,有人找我吗?
luobo_ljl
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:11 积分:175 威望:0 精华:0 注册:2017/1/2 13:49:00
累加多个单精度小数后,结果值无小数  发帖心情 Post By:2017/1/22 13:22:00 [只看该作者]

请问老师,累加多个单精度小数后,结果值无小数是怎么回事呢?

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/1/22 13:25:00 [只看该作者]

 如果是列,你试试改成双精度或者高精度。

 

 如果你写的是代码,看看你是不是赋值给整数了。


 回到顶部
帅哥哟,离线,有人找我吗?
luobo_ljl
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:11 积分:175 威望:0 精华:0 注册:2017/1/2 13:49:00
  发帖心情 Post By: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
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:517 积分:4199 威望:0 精华:0 注册:2009/10/8 16:43:00
  发帖心情 Post By:2017/1/22 15:23:00 [只看该作者]

没有定义t3


 回到顶部
帅哥哟,离线,有人找我吗?
luobo_ljl
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:11 积分:175 威望:0 精华:0 注册:2017/1/2 13:49:00
  发帖心情 Post By: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
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:11 积分:175 威望:0 精华:0 注册:2017/1/2 13:49:00
  发帖心情 Post By:2017/1/22 15:28:00 [只看该作者]

一开始就定义了

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/1/22 18:19:00 [只看该作者]

试试定义成这样

 

Dim nx3 As Double = 0
Dim nx4 As Double = 0
Dim nx5 As Double = 0
Dim nx6 As Double = 0


 回到顶部