There are many places in my project where I try to display currency with the built-in {0:C}
currency format. If the number is negative, it surrounds the value in parentheses. I want it to use a negative sign instead.
My web.config has culture set to auto
, and it resolves to en-US
.
The ideal solution would be some global web.config or other setting that would make the {0:C}
display the negative sign for the en-US
culture, but I'm open to other, less awesome solutions as well.
The negative sign before the number but behind the currency symbol. The negative sign after the number. Enclosed in parentheses.
Select the cell or range of cells that you want to format with a negative number style. In the Category box, click either Number or Currency. Under Negative numbers, select an option for negative numbers.
The standard accounting way is always to show negative numbers in parentheses. If you want to appeal to primarily financial professionals, that's the accepted practice. She also cautions against using red or drawing attention to a negative number.
Using a Number Line to Add Integers Look Out: sometimes you may see parentheses around negative numbers. These do not mean that we need to multiply; they're just used so that we don't confuse negatives with subtraction.
You have to specify the correct NumberFormatInfo.CurrencyNegativePattern
which is probably 1.
Decimal dec = new Decimal(-1234.4321); CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); culture.NumberFormat.CurrencyNegativePattern = 1; String str = String.Format(culture, "{0:C}", dec); Console.Write(str);
demo: http://ideone.com/HxSqT
output:
-$1,234.43
I think a combination of the answers here will get you closer to what you want.
protected void Application_BeginRequest() { var ci = CultureInfo.GetCultureInfo("en-US"); if (Thread.CurrentThread.CurrentCulture.DisplayName == ci.DisplayName) { ci = CultureInfo.CreateSpecificCulture("en-US"); ci.NumberFormat.CurrencyNegativePattern = 1; Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; } }
If you want to not have any code that deals with a single culture like this... I believe you need to build your own culture... Check this Question
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