Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Sub floatTest()
Dim dblVar As Single
dblVar = 5.731 / 8
dblOutput dblVar
dblVar = dblVar * 2
dblOutput dblVar
dblVar = dblVar * 2
dblOutput dblVar
dblVar = dblVar * 2
dblOutput dblVar
dblVar = dblVar * 2
dblOutput dblVar
dblVar = dblVar * 2
dblOutput dblVar
End Sub
Public Sub dblOutput(ByVal dblVar As Single)
Dim bytVar(3) As Byte
Dim i As Integer, j As Integer
Dim strVar As String
CopyMemory ByVal VarPtr(bytVar(0)), ByVal VarPtr(dblVar), 4
strVar = dblVar & ": "
For i = 3 To 0 Step -1
For j = 7 To 0 Step -1
strVar = strVar & (bytVar(i) And 2 ^ j) / 2 ^ j
Next j
strVar = strVar & " "
Next i
Debug.Print strVarEnd Sub
.716375: 00111111 00110111 01100100 01011010
1.43275: 00111111 10110111 01100100 01011010
2.86550: 01000000 00110111 01100100 01011010
5.73100: 01000000 10110111 01100100 01011010
11.4620: 01000001 00110111 01100100 01011010
22.9240: 01000001 10110111 01100100 01011010
以下是引用laowu在2005-9-6 1:49:00的发言:
好文章,顶!
以下是引用wang1950317在2005-9-6 16:41:00的发言:
高深!
以下是引用Grant在2005-9-6 3:46:00的发言:
非常的好,佩服!佩服!看了这文章才知道单/双精度数有此缺陷.
以下是引用secowu在2005-9-7 11:36:00的发言:
那用什么才能精确呢?
比如:我的数据格式有三位的:
0.032
1.231
1.285
0.128
那么该如何给这个字段设定类型?
以下是引用LucasLynn在2005-9-7 12:29:00的发言:
1、货币类型
2、都乘以1000存储。其实货币类型本身就是浮点整数。
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |