Excel number format to only show decimals when necessary

后端 未结 6 1181
旧巷少年郎
旧巷少年郎 2021-01-12 00:32

How can I, without using formulas, show integers as integers, but decimals limited to a specific number of decimal places.

e.g. show: 1 as 1

6条回答
  •  情话喂你
    2021-01-12 00:48

    Maybe an example used to put coordinates to a point could help.

    Sub PutCoord(PtN&, Px#, Py#, S4$)
    
    Px = Round(Px, 2): Py = Round(Py, 2)
    
     Dim XS$: If Px = Int(Px) Then XS = Format(Px, "0") Else XS = Format(Px, "0.##")
    
     Dim YS$: If Py = Int(Py) Then YS = Format(Py, "0") Else YS = Format(Py, "0.##")
    
       Dim WS$: WS = "Pt " & PtN & " @ " & XS & " , " & YS
    
       With ActiveSheet.Shapes.AddShape(msoShapeDoubleBracket, Px, Py, 90, 20)
    
          With .TextFrame
    
             .MarginLeft = 0
    
             .MarginRight = 0
    
             .MarginTop = 0
    
             .MarginBottom = 0
    
             .Characters.Text = WS
    
             .AutoSize = msoAutoSizeShapeToFitText
    
          End With
    
          .Name = S4 & PtN
    
       End With
    
    End Sub
    

提交回复
热议问题