String.Format 和 log.DebugFormat 货币

发布于 2024-08-02 19:54:00 字数 169 浏览 2 评论 0原文

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

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

结果是

“Balance: ¤1,000.00”

为什么出现奇数字符而不是 $

I'm using log4net to output a formatted message. The following code

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

results in

"Balance: ¤1,000.00"

Why is the odd character appearing and not a $

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2024-08-09 19:54:00

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

尝试这样的方法:

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 ¤ or numeric character reference ¤ may be used.

I would imagine that it is something to do with your regional settings.

Try something like this:

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

If that dosen't work then you can always use the debugger to check the value of:

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

Specifically check the value of:

ansiCurrencySymbol

To ensure that it's set to the '$' symbol.

You may also be intersted in this wikipedia page: http://en.wikipedia.org/wiki/Currency_%28typography%29

Which explains what the symbol you are getting is.

Specifically:

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 ¤ or numeric character reference ¤ may be used.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文