Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Created June 24, 2015 07:40
Show Gist options
  • Save idiotandrobot/b35f39338af0957b9e4e to your computer and use it in GitHub Desktop.
Save idiotandrobot/b35f39338af0957b9e4e to your computer and use it in GitHub Desktop.
Percentage IValueConverter
public class PercentageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var fraction = decimal.Parse(value.ToString());
return fraction.ToString("P1");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var valueWithoutPercentage = value.ToString().TrimEnd(' ', '%');
return decimal.Parse(valueWithoutPercentage) / 100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment