Format格式
我想用Format函数把数字变成指定格式。例如:1000->1,000
1050.2->1,050.2
1000.23->1,000.23
就是说我要加千位分隔符,并且根据实际的位数显示小数
请指教! --------------------编程问答-------------------- formt(val, "#,##0.##") --------------------编程问答-------------------- 这样子的话,如果没有小数的数字,最后会有一个小数点。 --------------------编程问答-------------------- Format(x, "#,#.########")
小数点后最常保留几位,就写几个# --------------------编程问答-------------------- 然后
if right(s,1) = "." then
s = left(s,len(s)-1)
end if --------------------编程问答--------------------
--------------------编程问答-------------------- dim x as double
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 Pay
End Sub
x = 1000
dim s as string
s = Format(x, "#,#.########")
if right(s,1) = "." then
s = left(s,len(s)-1)
end if
--------------------编程问答-------------------- 5楼正解。 --------------------编程问答-------------------- 3,4 楼吧, 楼主不要。00 --------------------编程问答--------------------
没有发现你说的问题、 --------------------编程问答-------------------- Format(strP,"0,000,000.00") --------------------编程问答--------------------
确实有. --------------------编程问答--------------------
Private Sub Command1_Click()--------------------编程问答-------------------- 是不是不同版本或DLL的问题?? --------------------编程问答--------------------
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
补充:VB , 基础类