在全球范围内不断变化的负面货币数字格式在C# [英] Globally changing format of negative currency numbers in C#

查看:121
本文介绍了在全球范围内不断变化的负面货币数字格式在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在那里所有的数字输出到屏幕上的(即的ToString(C)格式化为货币大量的ASP.NET MVC项目然而,负数都出现了()的,例如:

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;

我们倒是preFER不改变我们所有的ToString(C)的方法...有没有更好的办法?我首先想到的是仅仅改变我们的语言环境到澳大利亚,但实现的日期格式会被搞砸了。

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接近...试试这个在你的基地控制器:

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;

这篇关于在全球范围内不断变化的负面货币数字格式在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆