This may be something similar to other but my understanding is not great so I'm trying to see if anyone can help me understand. I want to change the decimal place of a number, for example if the number is 0.5 I want it to convert it to .50, likewise if it was 0.25 then .25, etc, I'm guessing this is so simple but I can't seem to understand how to do this? My unit test code I have is below and the first one passes but not the others
Updated Unit Test
[TestFixture]
public class ProbabilityDisplayConverterTests
{
public ProbabilityDisplayConverter underTest = new ProbabilityDisplayConverter();
[Test]
public void Convert_ConvertsWholeDecimal()
{
var value = (string)underTest.Convert(1, typeof(decimal), null, CultureInfo.CurrentCulture);
Assert.AreEqual("1", value);
}
[Test]
public void Convert_ConvertsHalfToDecimal()
{
var value = (string)underTest.Convert(0.5, typeof(decimal), null, CultureInfo.CurrentCulture);
Assert.AreEqual(".50", value);
}
[Test]
public void Convert_ConvertsDecimal()
{
var value = (string)underTest.Convert(0.25, typeof(decimal), null, CultureInfo.CurrentCulture);
Assert.AreEqual(".25", value);
}
[Test]
public void Convert_ConvertsWholeNumberDecimal()
{
var value = (string)underTest.Convert(0.3, typeof(decimal), null, CultureInfo.CurrentCulture);
Assert.AreEqual(".30", value);
}
}
EDIT
public class ProbabilityDisplayConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value = value.ToString("G", CultureInfo.InvariantCulture);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}