然后 if right(s,1) = "." then s = left(s,len(s)-1) end if
Private Sub Command1_Click() Dim Pay As Double 'str=1000->1,000 '1050.2->1,050.2 '1000.23->1,000.23 Pay = Format(1000.23, "##,##0.00")Debug.Print PayEnd Sub
dim x as double x = 1000dim s as string s = Format(x, "#,#.########") if right(s,1) = "." then s = left(s,len(s)-1) end if
Private Sub Command1_Click() Dim a! a = 1000 Debug.Print IIf(Fix(a) = a, a, Format(1000, "##,##0.00")) End Sub
是不是不同版本或DLL的问题??
Dim x As Variant x = 1000 x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####")) Debug.Print x x = 1050.2 x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####")) Debug.Print x x = 1000.23 x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####")) Debug.Print x
小数点后最常保留几位,就写几个#
if right(s,1) = "." then
s = left(s,len(s)-1)
end if
Private Sub Command1_Click()
Dim Pay As Double
'str=1000->1,000
'1050.2->1,050.2
'1000.23->1,000.23
Pay = Format(1000.23, "##,##0.00")Debug.Print PayEnd Sub
x = 1000dim s as string
s = Format(x, "#,#.########")
if right(s,1) = "." then
s = left(s,len(s)-1)
end if
Dim a!
a = 1000
Debug.Print IIf(Fix(a) = a, a, Format(1000, "##,##0.00"))
End Sub
Dim x As Variant
x = 1000
x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####"))
Debug.Print x
x = 1050.2
x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####"))
Debug.Print x
x = 1000.23
x = IIf(Int(x) = x, Format(x, "#,###"), Format(x, "#,##0.####"))
Debug.Print x