We have a large ASP.NET MVC project where all numbers output to the screen are formatted as currency (i.e. ToString("c"). However, negative numbers are showing up with ()'s. For example:
decimal d = -8.88m;
Console.WriteLine(d.ToString("c"));
//outputs $(8.88)
This is a bit annoying to our users, particularly since there are in textboxes. We have a few thousand places where we send currency fields to the screen like this, so we'd love a way to change the formatting globally. Is there one? All the methods I've seen indicate that you have to create a new formatter, similar to this:
string curCulture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
System.Globalization.NumberFormatInfo currencyFormat =
new System.Globalization.CultureInfo(curCulture).NumberFormat;
currencyFormat.CurrencyNegativePattern = 1;
We'd prefer not to change all of our ToString("c") methods ... is there a better way? My first thought was to just change our locale to Australia, but realized the date formatting would be screwed up.
Aliostad was close ... try this in your base controller:
System.Globalization.CultureInfo modCulture = new System.Globalization.CultureInfo("en-US");
modCulture.NumberFormat.CurrencyNegativePattern = 1;
Thread.CurrentThread.CurrentCulture = modCulture;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With