1
我想在帶兩位小數的文本框中顯示小數點。當頁面加載文本框中的值時顯示兩位小數(「0.00」)。當我將數值改爲10時,它僅顯示爲10.我如何顯示它爲「10.00」Silverlight轉換器顯示兩位小數點
以下是我的轉換器。
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
decimal convertedBudget;
if (value == null)
{
convertedBudget = 0.0M;
}
else
{
convertedBudget = (decimal)value;
}
return string.Format("{0:#,0.00}", Math.Round(convertedBudget, 2));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
decimal convertedBudget = 0;
if(value!=null && !string.IsNullOrEmpty(value.ToString()))
{
convertedBudget = System.Convert.ToDecimal(value.ToString());
}
return Math.Round(convertedBudget, 2);
}
在此先感謝
@StawWho我試圖用相同的StringFormat = 'N2',但加載頁面時,它只是顯示小數。當我將該值更改爲其他數字時,小數點不顯示。 – Shrikey 2013-03-15 12:53:45
更新完整的工作示例 – StaWho 2013-03-15 13:06:33
@Stawwho欣賞你的代碼..但只是在文本框中手動輸入5並失去其焦點。它仍然顯示爲5.我希望顯示爲「5.00」。 – Shrikey 2013-03-15 13:16:08