This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Convert Double To Currency Snippet (ArcObjects .NET 10.4 SDK) |
Convert a number that is a Double into a well formatted Currency String.
/// <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; }
''' <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