String.Format and log.DebugFormat Currency

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

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

      

leads to

"Balance: ¤1,000.00"

Why does odd character appear and not $

+2


source to share


1 answer


I would guess it has 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 doesn't work, you can always use the debugger to check the value:

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

Specifically check the value:



ansiCurrencySymbol

      

To make sure it is set to the $ symbol.

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

This explains what character you are getting.

In particular:

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.

      

+1


source







All Articles