首页 文章

Excel 2013在分配浮点时舍入单元格值

提问于
浏览
0

我有一个包含6位小数的数字的单元格,我希望将其分配给另一个工作表的单元格,精度为5位小数 . 我使用相同的变量两次,它在我第一次进行赋值时正常工作,但在Cells Value的第二个赋值语句中,对于一个double变量,该值自动舍入到四个小数位 . 我没有Excel选项来使用显示的precisoin打开 .

Dim i As Long, x As Long, round_prc As Double
Dim WSTarget As Worksheet

        'OE Price
        round_prc = Round(.Cells(3 + x, 9).Value, 5)    ; six decimals assigned to 5 decimals
        WSTarget.Cells(1 + i, 10).Value = round_prc

       'New Price
        round_prc = .Cells(3 + x, 13).Value     ; six decimals assigned to 4 decimals??????
        round_prc = Round(.Cells(3 + x, 13).Value, 5)
        WSTarget.Cells(1 + i, 12).Value = round_prc

更新:单元格格式与OE价格和新价格不同 . 新价格包括$ . 当我删除$该任务不再回合 . 为什么货币会自动舍入到4位小数?有谁能解释一下?

1 回答

  • 2

    我解决了我的问题 . 单元格形成货币的事实迫使.Value四舍五入到小数点后4位 . .Value2属性没有这样的约束 . 从而....

    'OE Price              a general formatted cell
            round_prc = Round(.Cells(3 + x, 9).Value, 5)   'rounded only by the function
            WSTarget.Cells(1 + i, 10).Value = round_prc
    
    
            'New CCA Price         a currency formatted cell
            round_prc = .Cells(3 + x, 13).Value            'rounded to 4 decimals
            round_prc = .Cells(3 + x, 13).Value2           'Not rounded
            round_prc = Round(.Cells(3 + x, 13).Value2, 5)
            WSTarget.Cells(1 + i, 12).Value = round_prc
    

    我希望这有助于其他可能遇到此问题的人 .

相关问题