Friday, January 4, 2013

Display and Format Negative Currency value

Shout it kick it on
This small tip about how to show the negative currency value in your application. For Example if you have currency value like -1234 and you want to display it like -$1,234 according to you culture.

In C# to one of the way to format currency value easily is use ToString("c") with value will do work for you. For example check below code
//format -1234 as currency..

This will display value in output like this ($1,234.00). But the actual problem with the formatting is its not displaying - sign with currency value.

So to come out of this You need to create a custom NumberFormatInfo from your current locale. Then you can specify it's CurrencyNegativePattern, for example:
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo newCulture = new CultureInfo(currentCulture.Name);
newCulture.NumberFormat.CurrencyNegativePattern = 1;
Thread.CurrentThread.CurrentCulture = newCulture;

Now output of the above code is -$1,234.00. That's what actually needed display negative sign for negative currency value.
So in above code actual trick done by NumberFormatInfo.CurrencyNegativePattern Property, which is set to 1 which associated with pattern -$n. There number of different pattern supported which you can check on MSDN and assign value to property according to your need. This will not affect positive value of currency i.e. if you pas 1234 as value its dispaly as $1,234 only. And for this this example my current culture is "en-US" .

I Hope you all like this simple and easy example of formatting negative currency. you can explore more on MSDN on reference provided at end of post.
NumberFormatInfo Class
NumberFormatInfo.CurrencyNegativePattern Property -

Leave comment if you have any query or if you like it.


  1. But with optimal nutгitional plan wheгe
    уou rаpidly lоse weight wіthout how to grow
    tallеr, they arе ρrogгammed dіfferently, аnd other diseaѕe.

    I can do to burn fаt.

    Feel free to visіt my web sіtе:
    My page: Growth Plates

  2. Тhere have been reviews of the top 3 rеason ωhy you would
    be to make sure they don't have any unnatural additives. Make an appointment with your doctor before taking any Weight Loss Pills For Men. Green tea and green weight loss pills for mens offer a number of different retailers, both on and offline. Furthermore, the highest weight loss tends to be in so that it is nutritious.

    Also visit my blog post ...

  3. We contracted a local business to do my search engine optimisation and about
    a month later I checked and our website had lost a lot of traffic,
    not a good sign I assume?
    I will definitely be returning, its a great site

  4. My family always say that I am killing my time here at web, but I
    know I am getting experience everyday by reading such fastidious articles.

    my website - dummy variable

  5. Hello, I enjoy reading all of your post. I wanted to write a little comment to support

    Take a look at my web site :: live sex cams

  6. Woah! I'm really enjoying the template/theme of this blog.
    It's simple, yet effective. A lot of times it's hard to get that "perfect balance" between superb usability and visual
    appeal. I must say you have done a excellent job with this.
    In addition, the blog loads extremely quick for me on Internet explorer.
    Exceptional Blog!

    my blog post ... cross rings (

  7. Kesempatan selalu ada Obat Kutil Kelamin. Biarkan kailmu terus siaga didalam Penyakit Sipilis Pada Pria kolam yg paling tidak kau harapkan, Tanda tanda Penyakit Kencing Nanah seringkali ikan berada di sana.