I am trying to make a column in WPF datagrid to display currency in the following format:
value <= 9999, display format set to $1,234;
value <= 99999, display format set to $12k;
value >99999, display format set to $12M;
In addition, I would need to have the function that user can see the actual value and edit the value upon mouse click.
I have been trying to get the concept of IValueConverter, but couldn't get a working code.
Can someone help?
Update: with Ramin's answer, it is partially working. Here are the code:
public class DollarConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double v = double.Parse(value.ToString());
if (v <= 9999)
{
return v.ToString("C0");
}
else if (v <= 999999)
{
double vv = v / 1000;
return vv.ToString("C0") + "K";
}
else if (v > 99999)
{
double vvv = v / 1000000;
return vvv.ToString("C0") + "M";
}
return v;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
in WPF:Binding="{Binding LBRRev, Converter={StaticResource DollarConverter}}"