Created
June 24, 2015 07:40
-
-
Save idiotandrobot/b35f39338af0957b9e4e to your computer and use it in GitHub Desktop.
Percentage IValueConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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