String.Format和log.DebugFormat货币

时间:2009-08-26 19:47:26

标签: c# log4net

我正在使用log4net输出格式化的消息。以下代码

log.DebugFormat("Balance: {0:c} ", balance);

结果

“余额:¤1,000.00”

为什么出现奇怪的角色而不是$

1 个答案:

答案 0 :(得分:1)

我认为这与您的区域设置有关。

尝试这样的事情:

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(<your culture setting>);
log.DebugFormat("Balance: {0:c} ", balance);

如果这不起作用,那么您始终可以使用调试器来检查以下值:

System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat;

具体检查以下值:

ansiCurrencySymbol

确保将其设置为“$”符号。

您可能还会参与此维基百科页面:http://en.wikipedia.org/wiki/Currency_%28typography%29

这解释了你得到的符号是什么。

具体做法是:

The currency sign (¤) is a character used to denote a currency, when the symbol for a particular currency is unavailable. 

It is particularly common in place of symbols, such as that of the Colón (₡), which are absent from most character sets and fonts. 

It can be described as a circle the size of a lowercase character with four short radiating arms at 45° (NE), 135° (NW), 225°, (SW) and 315° (SE). It is slightly raised over the baseline.

It is represented in Unicode, as CURRENCY SIGN (U+00A4). In HTML, the character entity reference &curren; or numeric character reference &#164; may be used.