ArcObjects Library Reference  (System)    

NumericFormat Example

  1. Copy the code below.
  2. In ArcMap, select Macros... from Tools | Macros (or press Alt-F8).
  3. Enter a new macro name and click the Create button.
  4. Paste the copied code into the code pane.
  5. Press F5 to run the macro.
[Visual Basic 6.0]
Sub NumericFormatExample() ' Define options in the INumericFormat interface. ' NumericFormat is the coclass -- use New to set this. Dim pNumericFormat As INumericFormat Set pNumericFormat = New NumericFormat With pNumericFormat .AlignmentOption = esriAlignRight .RoundingOption = esriRoundNumberOfDecimals .AlignmentWidth = 15 .RoundingValue = 5 .ShowPlusSign = True .UseSeparator = True .ZeroPad = False End With ' ValueToString & StringToValue methods are in the ' INumberFormat interface. QI for INumberFormat to ' use them. Dim pNumberFormat As INumberFormat Set pNumberFormat = pNumericFormat ' Show some examples Dim dValue As Double, sV2S As String, dS2V As Double For dValue = 100.0123 To 1000101 Step 200000 ' ValueToString() returns a formatted string, but ' does not change the passed in numerical value sV2S = pNumberFormat.ValueToString(dValue) ' StringToValue() translates formatted ' strings back to a numerical value dS2V = pNumberFormat.StringToValue(sV2S) MsgBox "ValueToString(" & dValue & ") = '" & sV2S & "'" & vbNewLine & _ "StringToValue('" & sV2S & "') = " & dS2V, , _ "NumericFormat" Next End Sub

[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button Language Filter in the upper-left corner of the page.