Your problem really arises from the presentation of space in digital format. The space in which you are experiencing problems is defined in NumberFormatInfoclass' CurrencyGroupSeparator. If you check the character codes of both the standard ASCII space and the section separator of a currency group with the following fragment
Console.WriteLine("Space code: {0}", (Int32)' ');
var separator = Thread.CurrentThread.CurrentCulture.NumberFormat
.CurrencyGroupSeparator;
Console.WriteLine("Currency separator code: {0}", (Int32)separator[0]);
... , 32 160 . .
ASCII, :
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyGroupSeparator = " ";
. , , unit test. , , . ( ), , :
public static string FormatCurrency(this decimal instance)
{
return instance.FormatCurrency(Thread.CurrentThread.CultureInfo);
}
public static string FormatCurrency(this decimal instance, CultureInfo culture)
{
return string.Format(culture, "{0:c}", instance);
}
unit test , (, , ):
[Test]
public void FormatCurrency_should_return_formatted_decimal_string()
{
decimal amount = 1000;
var culture = CultureInfo.CreateSpecificCulture("en-us");
culture.NumberFormat.CurrencyGroupSeparator = " ";
string actual = amount.FormatCurrency(culture);
Assert.AreEqual("$1 000.00", actual);
}
.