This document is archived and information here might be outdated.  Recommended version.


Currency Format Example Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Currency Format Example Snippet

Display sample currecny values as both a Double .ToString and a well formatted string.

[C#]
/// <summary>
/// Display sample currecny values as both a Double .ToString and a well formatted string.
/// </summary>
/// <remarks></remarks>
public void CurrencyFormatExample()
{

  ESRI.ArcGIS.esriSystem.INumberFormat numberFormat=new ESRI.ArcGIS.esriSystem.CurrencyFormatClass();

  // Use the ValueToString method to format numbers. 
  System.Double double_UnformattedNumber=0;
  System.String string_ValueToString=null;
  System.Double double_StringToValue=0;

  for (double_UnformattedNumber=100.567; double_UnformattedNumber <= 1000101; double_UnformattedNumber += 200000)
  {
        // ValueToString() returns a formatted string, but does not change the passed in numerical value
        string_ValueToString=numberFormat.ValueToString(double_UnformattedNumber);

        // StringToValue() translates formatted strings back to a numerical value
        double_StringToValue=numberFormat.StringToValue(string_ValueToString);

        System.Windows.Forms.MessageBox.Show("ValueToString(" + double_UnformattedNumber + ")='" + string_ValueToString + "'" + System.Environment.NewLine + "StringToValue('" + string_ValueToString + "')=" + double_StringToValue, "CurrencyFormat");
  }
}
[Visual Basic .NET]
''' <summary>
''' Display sample currecny values as both a Double .ToString and a well formatted string.
''' </summary>
''' <remarks></remarks>
Sub CurrencyFormatExample()

  Dim numberFormat As ESRI.ArcGIS.esriSystem.INumberFormat=New ESRI.ArcGIS.esriSystem.CurrencyFormatClass

  ' Use the ValueToString method to format numbers. 
  Dim double_UnformattedNumber As System.Double
  Dim string_ValueToString As System.String
  Dim double_StringToValue As System.Double

  For double_UnformattedNumber=100.567 To 1000101 Step 200000
    ' ValueToString() returns a formatted string, but does not change the passed in numerical value
    string_ValueToString=numberFormat.ValueToString(double_UnformattedNumber)

    ' StringToValue() translates formatted strings back to a numerical value
    double_StringToValue=numberFormat.StringToValue(string_ValueToString)

      System.Windows.Forms.MessageBox.Show("ValueToString(" + double_UnformattedNumber.ToString + ")='" + string_ValueToString + "'" + System.Environment.NewLine + _
           "StringToValue('" + string_ValueToString + "')=" + double_StringToValue.ToString, "CurrencyFormat")
  Next
End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.System
  • System
  • System.Windows.Forms