I expect both tests below (written for NUnit) to pass, but the Decimal version fails with, "System.FormatException: Format specifier was invalid", as does a Double version. I cannot figure out why. Can someone please shed light?
Thanks; Duncan
[Test]
public void Integer_Format_Hex()
{
//Assume
Int32 myValue = 11101110;
//Arrange
//Act
//Assert
Assert.That( String.Format( "0x{0:X8}" , myValue ) , Is.EqualTo( "0x00A963B6" ) );
}
[Test]
public void Decimal_Format_Hex()
{
//Assume
Decimal myValue = 11101110m;
//Arrange
//Act
//Assert
Assert.That( String.Format( "0x{0:X8}" , myValue ) , Is.EqualTo( "0x00A963B6" ) );
}
[Test]
public void Decimal_Format_Hex2()
{
//Assume
Decimal myValue = 11101110m;
//Arrange
//Act
//Assert
Assert.That( myValue.ToString( "X" ) , Is.EqualTo( "00A963B6" ) );
}
Exerpt from http://msdn.microsoft.com/en-us/library/fzeeb5cd(v=VS.90).aspx
"The format parameter can be any valid standard numeric format specifier except for D, R, and X...."
Awesome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With