Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format an int as currency in C#?

I want to format an int as a currency in C#, but with no fractions. For example, 100000 should be "$100,000", instead of "$100,000.00" (which 100000.ToString("C") gives).

I know I can do this with 100000.ToString("$#,0"), but that's $-specific. Is there a way to do it with the currency ("C") formatter?

like image 610
Ken Avatar asked Jan 10 '09 02:01

Ken


People also ask

How to format a number as currency in C#?

The "C" (or currency) format specifier is used to convert a number to a string representing a currency amount. Let us see an example. double value = 139.87; Now to display the above number until three decimal places, use (“C3”) currency format specifier.

Which of the following objects have an effect on .NET handling dates formatting and Unformatting issues currencies etc?

CurrentCulture handles dates,currencies,sorting and formatting issues in Dot Net.


3 Answers

Use format "C0".

like image 92
jfs Avatar answered Oct 21 '22 14:10

jfs


Possible to use n0 which provide commas like 1,234. Currency sign won't be there

like image 2
Henry Vilinskiy Avatar answered Oct 21 '22 15:10

Henry Vilinskiy


try

using System.Globalization
@string.Format(new CultureInfo("en-IN"), "{0:c}", moneyvalue)

wil show the format in Rs.

like image 1
Suraj Shrestha Avatar answered Oct 21 '22 15:10

Suraj Shrestha