Public Function daxie(M As Double) '这样定义数字为双精度之后,返回的结果就不会出错了!相应地,在调用此自定义函数之前,也应该对变量定义为双精度的。 Dim Y, j, f, a, b, c As Variant Y = Int(Round(100 * Abs(M)) / 100) j = Round(100 * Abs(M) + 0.00001) - Y * 100 f = Round((j / 10 - Int(j / 10)) * 10) a = IIf(Y < 1, "", Application.Text(Y, "[DBNum2]") & "元") b = IIf(j > 9.4, Application.Text(Int(j / 10), "[DBNum2]") & "角", IIf(Y < 1, "", IIf(f > 0.4, "零", ""))) c = IIf(f < 1, "整", Application.Text(Round(f, 0), "[DBNum2]") & "分") daxie = IIf(Abs(M) < 0.005, "", IIf(M < 0, "负" & a & b & c, a & b & c)) End Function Sub ss() Dim vv As Double vv = 2000000000001.18 Debug.Print daxie(vv) End Sub '显示结果:贰兆零壹元壹角捌分
[此贴子已经被作者于2008-3-15 0:30:45编辑过] |