4
我希望下面的兩個測試(針對NUnit編寫)都可以通過,但Decimal版本的失敗是「System.FormatException:格式說明符無效」,正如Double版本一樣。我無法弄清楚爲什麼。有人可以擺脫燈光嗎?十進制值的String.Format扼流圈?
謝謝; 鄧肯
[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"));
}
尊敬的甜jeebus方法名稱 – Woot4Moo 2010-11-08 18:24:18
可能重複的[如何在十六進制和十進制數字之間轉換數字](http://stackoverflow.com/questions/74148/how-to-convert-numbers-between-hex-and -decimal-in-c) – NotMe 2010-11-08 18:25:24
@ Woot4Moo:無參數! @Chris Lively:這當然是相關的,但是您提供的鏈接中的代碼示例在使用時顯示爲FAIL。 – Duncan 2010-11-08 18:32:54