大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Option Explicit
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了自流井免费建站欢迎大家使用!
Private Type qx
zs As Long
xs As Single
End Type
Private Sub Command1_Click()
Call xs(100.365)
End Sub
Function xs(a As String)
Dim i As Integer, xx As qx
i = InStr(1, a, ".")
xx.xs = Mid(a, i, Len(a) - i + 1)
xx.zs = Mid(a, 1, i - 1)
Print a + " 整数部分" + CStr(xx.zs) + "小数部分" + CStr(xx.xs)
End Function
先把x化为整数,然后取右边3位,得到y,y/100的整数赋给a
同理,先把x化为整数,然后取右边2位,得到y,y/10的整数赋给b
Private Sub Command1_Click()
Dim b(1 To 6) As String, myBstr(1 To 6) As String, myOutput(1 To 6) As String, myTempStr As String, myData As Long, myResult As String, a As Integer, i As Integer, j As Integer, k As Integer
'Open App.Path "\3d.txt" For Input As #1
'读入a值,应该不难吧
'Close
myData = 250663235: a = 789 'a值根据从文件读入的值变化
myResult = Replace(StrReverse(Format(myData / a, "0.000000")), ".", "")
For i = 1 To 6
b(i) = Left(myResult, 1)
myResult = Replace(myResult, b(i), "")
Next
myBstr(1) = b(1)
For i = 2 To 6
myBstr(i) = myBstr(i - 1) b(i)
Next
For i = 0 To 999
For j = 1 To 3
myTempStr = Mid(Format(i, "000"), j, 1)
For k = 1 To 6
If InStr(1, myBstr(k), myTempStr) 0 Then myOutput(k) = myOutput(k) IIf(InStr(1, myOutput(k), Format(i, "000")) 0, "", Format(i, "000") " ")
Next
Next
Next
For i = 1 To 6
Open App.Path "\" a "-" myBstr(i) ".txt" For Output As #1
Print #1, myOutput(i)
Close
Next
MsgBox "数据处理完毕"
End Sub
double是双精度 有效数值位52位 表示成指数的形式 即指数11位 即表示成
所以180.89305用2进制表示是10110100.1110010010011110111011001011111110110001010110110101
即
180.89305在double中存在的实际数值是
1.01101001110010010011110111011001011111110110001010110110101 *2^7
取小数点后 52位有效值后 等于10进制的180.893049999999998
所及加最后变成了 1808930.99999999998
第一次当然输出近似值1808931
第二次int函数去掉了小数点后的数int就是只取整数的部位的不是四舍五入 所以少了1
int在绝对值上四舍五入,Truncate在靠近0的方向取整,比如:
Sub Main()
Dim d = -1.9D
'Dim I As Integer = Int(d) '-2
Dim I As Integer = Math.Truncate(d) '-1
Console.WriteLine(I)
Console.ReadLine()
End Sub
有两个函数:Int 和 Fix。
Int 定义为返回不大于给定参数的最大整数值,如:
Int(3.9) = 3
Int(3.1) = 3
Int(3) = 3
Int(0) = 0
Int(-3) = -3
Int(-3.1) = -4
Int(-3.9) = -4
Fix 又称“截尾”函数。
即简单保留整数部分,如:
Fix(3.9) = 3
Fix(-3.9) = -3
如果需要“四舍五入”,则得巧妙利用 Int 函数:
Int(x + 0.5) 表示四舍五入到个位;
Int(x * 100 + 0.5) * 0.01 表示四舍五入到百分位(小数点后第二位)