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


Convert Double To Currency Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Convert Double To Currency Snippet

Convert a number that is a Double into a well formatted Currency String.

[C#]
/// <summary>
/// Convert a number that is a Double into a well formatted Currency String. 
/// </summary>
/// <param name="double_UnformattedNumber">A System.Double that is a currency value. Example: 123456.789</param>
/// <returns>A System.String that is a well formatted in the currecny format. Example: "$123,456.79"</returns>
/// <remarks></remarks>
public System.String ConvertDoubleToCurrency(System.Double double_UnformattedNumber)
{

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

  // Use the ValueToString method to format numbers. 
  System.String string_ValueToString=null;

  // ValueToString() returns a formatted string, but does not change the passed in numerical value
  string_ValueToString=numberFormat.ValueToString(double_UnformattedNumber);

  return string_ValueToString;

}
[Visual Basic .NET]
''' <summary>
''' Convert a number that is a Double into a well formatted Currency String. 
''' </summary>
''' <param name="double_UnformattedNumber">A System.Double that is a currency value. Example: 123456.789</param>
''' <returns>A System.String that is a well formatted in the currecny format. Example: "$123,456.79"</returns>
''' <remarks></remarks>
Public Function ConvertDoubleToCurrency(ByVal double_UnformattedNumber As System.Double) As System.String

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

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

  ' ValueToString() returns a formatted string, but does not change the passed in numerical value
  string_ValueToString=numberFormat.ValueToString(double_UnformattedNumber)

  Return string_ValueToString

End Function

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