<p>Is there a C# equivalent for the VB.NET <code>FormatNumber</code> function? </p>

<p>I.e.:</p>

<pre><code>JSArrayString += "^" + (String)FormatNumber(inv.RRP * oCountry.ExchangeRate, 2);
</code></pre>

[{'answer_id': 49476, 'author': 'd91-jal', 'author_id': 5085, 'author_profile': 'https://Stackoverflow.com/users/5085', 'pm_score': 1, 'selected': False, 'text': '<p>You can use string formatters to accomplish the same thing.</p>\n\n<pre><code>double MyNumber = inv.RRP * oCountry.ExchangeRate;\nJSArrayString += "^" + MyNumber.ToString("#0.00");\n</code></pre>\n'}, {'answer_id': 49479, 'author': 'John', 'author_id': 33, 'author_profile': 'https://Stackoverflow.com/users/33', 'pm_score': 4, 'selected': True, 'text': '<p>In both C# and VB.NET you can use either the <a href="http://www.java2s.com/Code/CSharp/Development-Class/UseToStringtoformatvalues.htm" rel="nofollow noreferrer">.ToString()</a> function or the <a href="http://www.java2s.com/Code/CSharp/Development-Class/UseStringFormattoformatavalue.htm" rel="nofollow noreferrer">String.Format()</a> method to format the text. </p>\n\n<p>Using the .ToString() method your example could be written as:</p>\n\n<pre><code>JSArrayString += "^" + (inv.RRP * oCountry.ExchangeRate).ToString("#0.00")\n</code></pre>\n\n<p>Alternatively using the String.Format() it could written as:</p>\n\n<pre><code>JSArrayString = String.Format("{0}^{1:#0.00}",JSArrayString,(inv.RRP * oCountry.ExchangeRate))\n</code></pre>\n\n<p>In both of the above cases I have used custom formatting for the currency with # representing an optional place holder and 0 representing a 0 or value if one exists.  </p>\n\n<p>Other formatting characters can be used to help with formatting such as D2 for 2 decimal places or C to display as currency. In this case you would not want to use the C formatter as this would have inserted the currency symbol and further separators which were not required.</p>\n\n<p>See "<a href="http://idunno.org/archive/2004/14/01/122.aspx" rel="nofollow noreferrer">String.Format("{0}", "formatting string"};</a>" or "<a href="http://www.csharp-examples.net/string-format-int/" rel="nofollow noreferrer">String Format for Int</a>" for more information and examples on how to use String.Format and the different formatting options.</p>\n'}, {'answer_id': 49486, 'author': 'DonkeyMaster', 'author_id': 5178, 'author_profile': 'https://Stackoverflow.com/users/5178', 'pm_score': 2, 'selected': False, 'text': '<p>Yes, the .ToString(string) methods.\nFor instance,</p>\n\n<pre><code>int number = 32;\nstring formatted = number.ToString("D4");\nConsole.WriteLine(formatted);\n// Shows 0032\n</code></pre>\n\n<p>Note that in C# you don\'t use a number to specify a format, but you use a character or a sequence of characters.\nFormatting numbers and dates in C# takes some minutes to learn, but once you understand the principle, you can quickly get anything you want from looking at the reference.</p>\n\n<p>Here\'s a couple MSDN articles to get you started :</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" rel="nofollow noreferrer">Standard Numeric Format Strings</a>\n<a href="http://msdn.microsoft.com/en-us/library/fbxft59x.aspx" rel="nofollow noreferrer">Formatting Types</a></p>\n'}, {'answer_id': 50641, 'author': 'Jonathan Allen', 'author_id': 5274, 'author_profile': 'https://Stackoverflow.com/users/5274', 'pm_score': 0, 'selected': False, 'text': '<p>While I would recommend using ToString in this case, always keep in mind you can use ANY VB.Net function or class from C# just by referencing Microsoft.VisalBasic.dll.</p>\n'}]
['https://Stackoverflow.com/questions/49461', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1583/']