Is there a C# equivalent for the VB.NET FormatNumber function?
I.e.:
JSArrayString += '^' + (String)FormatNumber(inv.RRP * oCountry.ExchangeRate, 2);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In both C# and VB.NET you can use either the .ToString() function or the String.Format() method to format the text.
Using the .ToString() method your example could be written as:
Alternatively using the String.Format() it could written as:
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.
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.
See ‘String.Format(‘{0}’, ‘formatting string’};‘ or ‘String Format for Int‘ for more information and examples on how to use String.Format and the different formatting options.