问问题
982 次
2 回答
0
try in this way
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var dValue = value as decimal?;
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
nfi.CurrencySymbol = "€";
return string.Format(nfi,"{0:c}",dValue)
}
if it doesn't work try without this line
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
if it doesn't work again try changing CurrencyNegativePattern Property and CurrencyPositivePattern Property with the value of 2
nfi.NumberFormat.CurrencyPositivePattern = 2;
nfi.NumberFormat.CurrencyNegativePattern = 2;
2 means "€ + number"
于 2014-11-27T15:43:07.827 回答
0
Try this (quick code, not really a unit test method, just to see the output).
[Test]
public void CurrencySymbolShouldAppearBeforeValue()
{
decimal price = 1370m;
var formatInfo = CultureInfo.GetCultureInfo("de-DE")
.NumberFormat.Clone() as NumberFormatInfo;
Assert.IsNotNull(formatInfo);
formatInfo.CurrencyPositivePattern = 2;
string formated = price.ToString("C3", formatInfo);
Assert.IsNotNull(formated);
}
Outputs: € 1.370,000
You can read more here.
于 2014-11-27T16:03:04.680 回答