我想用Format函数把数字变成指定格式。
例如:1000->1,000
1050.2->1,050.2
1000.23->1,000.23就是说我要加千位分隔符,并且根据实际的位数显示小数请指教!

解决方案 »

  1.   

    Format(x, "#,#.########")
    小数点后最常保留几位,就写几个#
      

  2.   

    然后
    if right(s,1) = "." then
      s = left(s,len(s)-1)
    end if
      

  3.   


    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
      

  4.   

    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
      

  5.   

    Private Sub Command1_Click()
        Dim a!
        a = 1000
        Debug.Print IIf(Fix(a) = a, a, Format(1000, "##,##0.00"))
    End Sub
      

  6.   

    是不是不同版本或DLL的问题??
      

  7.   


       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