ArcObjects Library Reference  (System)    

PercentageFormat 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 PercentageFormatExample() ' Create a PercentageFormat object and set PercentageFormat ' options through the IPercentageFormat interface Dim pPercentageFormat As IPercentageFormat Set pPercentageFormat = New PercentageFormat With pPercentageFormat .AdjustPercentage = True 'Value of 0.1 = 10% End With ' Set NumericFormat options through the INumericFormat interface. ' This step is not necessary unless you want to change the ' INumericFormat default properties. Comment this block of ' code out to see how it changes the format! Dim pNumericFormat As INumericFormat Set pNumericFormat = pPercentageFormat With pNumericFormat .AlignmentOption = esriAlignRight .RoundingOption = esriRoundNumberOfDecimals .AlignmentWidth = 16 .RoundingValue = 5 .ShowPlusSign = True .UseSeparator = False .ZeroPad = False End With ' The ValueToString & StringToValue methods are in the ' INumberFormat interface. QI for INumberFormat to ' use them. Dim pNumberFormat As INumberFormat Set pNumberFormat = pPercentageFormat '= pNumericFormat could be used here as well ' Format some values Dim dValue As Double, sV2S As String, dS2V As Double For dValue = 0 To 1 Step 0.25 sV2S = pNumberFormat.ValueToString(dValue) dS2V = pNumberFormat.StringToValue(sV2S) MsgBox "ValueToString(" & dValue & ") = '" & sV2S & "'" & vbNewLine & _ "StringToValue('" & sV2S & "') = " & dS2V, , _ "PercentageFormat - AdjustPercentage = " & pPercentageFormat.AdjustPercentage Next ' Set AdjustPercentage False to show how it changes things ' (Value of 0.1 = 0.1%) pPercentageFormat.AdjustPercentage = False For dValue = 0 To 1 Step 0.25 sV2S = pNumberFormat.ValueToString(dValue) dS2V = pNumberFormat.StringToValue(sV2S) MsgBox "ValueToString(" & dValue & ") = '" & sV2S & "'" & vbNewLine & _ "StringToValue('" & sV2S & "') = " & dS2V, , _ "PercentageFormat - AdjustPercentage = " & pPercentageFormat.AdjustPercentage 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.