.Value returns 货币格式的值只有小数点后4位
.Value returns only 4 decimal places of a value in currency format
我有以下 VBA 函数来从其他地方检索具有相同列但不同行的货币值:
Function GetValue(RefCell As Range) As Double
Dim i As Integer
i = Application.Caller.Column - RefCell.Column
Obtain = RefCell.Offset(0, i).Value
End Function
这是设置:
Column1 | Column2
Test 1 | 0.11111
Test 2 | [=12=].11111
使用 GetValue(Test1) 给了我 0.11111 美元,所有 5 位小数。但是,GetValue(Test2) 产生 $0.11110,只有前 4 位小数。如果输入是货币格式而不是数字格式,为什么函数只有 returns 4 位小数?我想从具有货币格式的单元格中检索所有小数位的最准确数字 - 即 $0.11111 而不是 $0.11110.
Range.Value property 具有一些区域货币特性;其中之一可能是 4 位精度(对于某些区域货币变量类型很常见)。
使用 Range.Value2 property 作为原始双精度值。
GetValue = RefCell.Offset(0, i).Value2
返回值可能必须手动设置为货币格式;任何区域信息都已被删除。
我有以下 VBA 函数来从其他地方检索具有相同列但不同行的货币值:
Function GetValue(RefCell As Range) As Double
Dim i As Integer
i = Application.Caller.Column - RefCell.Column
Obtain = RefCell.Offset(0, i).Value
End Function
这是设置:
Column1 | Column2
Test 1 | 0.11111
Test 2 | [=12=].11111
使用 GetValue(Test1) 给了我 0.11111 美元,所有 5 位小数。但是,GetValue(Test2) 产生 $0.11110,只有前 4 位小数。如果输入是货币格式而不是数字格式,为什么函数只有 returns 4 位小数?我想从具有货币格式的单元格中检索所有小数位的最准确数字 - 即 $0.11111 而不是 $0.11110.
Range.Value property 具有一些区域货币特性;其中之一可能是 4 位精度(对于某些区域货币变量类型很常见)。
使用 Range.Value2 property 作为原始双精度值。
GetValue = RefCell.Offset(0, i).Value2
返回值可能必须手动设置为货币格式;任何区域信息都已被删除。