2009-08-26 62 views
2

我使用log4net输出格式化消息。下面的代码String.Format和log.DebugFormat货币

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

结果

“余额:¤1,000.00”

为什么奇怪字符出现,而不是一个$

+1

你检查你的计算机上的区域设置? – Stephan 2009-08-26 19:53:16

+0

你在哪里登录? – 2009-08-26 19:54:18

+0

我真的认为它与log4net有关,因为它按预期工作。 log.Debug(String.Format(“Balance:{0:C}”,balance)); – Striker 2009-08-26 20:18:26

回答

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. 
+0

试过了,得到了同样的结果 – Striker 2009-08-26 20:09:14