문제

I want my values to be shown in the views

Like: -$150.00

Instead of: ($150.00)

--

I guess this is what I have to do:

How do I display a negative currency in red?

But I don't know what does he means by "BaseController class"

도움이 되었습니까?

해결책 2

So merging @Jon Skeet answer with this one

The Real Answer was to add this method to the Global.asax.cs file of your MVC Project. And that's it.

The key is the second line:

protected void Application_BeginRequest(object sender, EventArgs e)
        {

            CultureInfo culture = new CultureInfo("en-us");
            culture.NumberFormat.CurrencyNegativePattern = 1;    

            Thread.CurrentThread.CurrentUICulture = culture;
            Thread.CurrentThread.CurrentCulture = culture;
        }

다른 팁

It's all down to NumberFormatInfo.CurrencyNegativePattern. Presumably you've got the value 0, when it sounds like you want 1.

It's not clear whether you're currently using the user's CultureInfo, the server's one, or something else. But you could always clone whichever culture you're using, then modify the NumberFormatInfo.

Sample code:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        var original = new CultureInfo("en-us");
        // Prints ($5.50)
        Console.WriteLine(string.Format(original, "{0:C}", -5.50m));

        var modified = (CultureInfo) original.Clone();
        modified.NumberFormat.CurrencyNegativePattern = 1;        
        // Prints -$5.50
        Console.WriteLine(string.Format(modified, "{0:C}", -5.50m));
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top