當前位置: 首頁>>代碼示例>>C#>>正文


C# Amount.ConvertedTo方法代碼示例

本文整理匯總了C#中Amount.ConvertedTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Amount.ConvertedTo方法的具體用法?C# Amount.ConvertedTo怎麽用?C# Amount.ConvertedTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Amount的用法示例。


在下文中一共展示了Amount.ConvertedTo方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CustomConversion03Test

		public void CustomConversion03Test()
		{
			Unit kk = new Unit("kilokelvin", "kk", 1000, TemperatureUnits.DegreeKelvin);
			Amount t = new Amount(3m, kk);

			t = t.ConvertedTo(TemperatureUnits.DegreeCelcius);

			Assert.AreEqual(2726.85m, t.Value);
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:9,代碼來源:UnitManagerTests.cs

示例2: ComplexConversion02Test

		public void ComplexConversion02Test()
		{
			Amount kwh = new Amount(1000m, EnergyUnits.KiloWattHour);
			Amount gj = kwh.ConvertedTo(EnergyUnits.GigaJoule, 8);
			Console.WriteLine("{0} = {1}", kwh, gj);
			Assert.AreEqual(3.6m, gj.Value);
			Assert.AreEqual(EnergyUnits.GigaJoule, gj.Unit);
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:8,代碼來源:UnitManagerTests.cs

示例3: CustomConversion02Test

		public void CustomConversion02Test()
		{
			Amount t = new Amount(25, TemperatureUnits.DegreeCelcius);
			Console.WriteLine("Temperature : {0}", t);

			t = t.ConvertedTo(TemperatureUnits.DegreeFahrenheit, 4);
			Console.WriteLine("Temperature : {0}", t);

			t = t.ConvertedTo(TemperatureUnits.DegreeKelvin, 4);
			Console.WriteLine("Temperature : {0}", t);

			t = t.ConvertedTo(TemperatureUnits.DegreeCelcius, 4);
			Console.WriteLine("Temperature : {0}", t);

			Assert.AreEqual(new Amount(25, TemperatureUnits.DegreeCelcius), t);
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:16,代碼來源:UnitManagerTests.cs

示例4: ComplexConversion01Test

		public void ComplexConversion01Test()
		{
			Amount kh = new Amount(100m, LengthUnits.KiloMeter / TimeUnits.Hour);
			Amount ms = kh.ConvertedTo(LengthUnits.Meter / TimeUnits.Second, 4);
			Console.WriteLine("{0} = {1}", kh, ms);
			Assert.AreEqual(27.7778m, ms.Value);
			Assert.AreEqual(LengthUnits.Meter / TimeUnits.Second, ms.Unit);
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:8,代碼來源:UnitManagerTests.cs

示例5: Convert

			public Amount Convert(Amount amount)
			{
				return this.conversionFunction(amount.ConvertedTo(from));
			}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:4,代碼來源:UnitManager.cs

示例6: AmountComplexConvertPerformanceTest

		public void AmountComplexConvertPerformanceTest()
		{
			Amount a = new Amount(15m, (LengthUnits.KiloMeter * LengthUnits.Meter / LengthUnits.MilliMeter / (TimeUnits.Hour * TimeUnits.Minute / TimeUnits.MilliSecond)));
			Amount b = null;
			Unit targetUnit = LengthUnits.Meter / TimeUnits.Second;

			long t = Environment.TickCount;
			for (int n = 0; n < 100000; n++)
			{
				b = a.ConvertedTo(targetUnit, 8);
			}
			double time = (Environment.TickCount - t) / 1000.0;
			double var = (time - 0.203) / 0.203;

			Console.WriteLine("Original = {0}", a);
			Console.WriteLine("Result = {0}", b);
			Console.WriteLine("Time to perform 100K convertions: {0} sec.", time);
			Console.WriteLine("Variation: {0:0}%.", var * 100);

			Assert.AreEqual(0.06944444m, b.Value);

			Assert.IsTrue(var < MAX_ACCEPTABLE_VARIANCE, "Performance lost detected!");
			if (var < MIN_ACCEPTABLE_VARIANCE) Assert.Inconclusive("Performance was much better than expected.");
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:24,代碼來源:UnitPerformanceTests.cs

示例7: AmountSimpleConvertPerformanceTest

		public void AmountSimpleConvertPerformanceTest()
		{
			Amount a = new Amount(15m, LengthUnits.KiloMeter);
			Amount b = null;

			long t = Environment.TickCount;
			for (int n = 0; n < 100000; n++)
			{
				b = a.ConvertedTo(LengthUnits.Meter, 8);
			}
			double time = (Environment.TickCount - t) / 1000.0;
			double var = (time - 0.172) / 0.172;

			Console.WriteLine("Result = {0}", b);
			Console.WriteLine("Time to perform 100K convertions: {0} sec.", time);
			Console.WriteLine("Variation: {0:0}%.", var * 100);

			Assert.AreEqual(15000m, b.Value);

			Assert.IsTrue(var < MAX_ACCEPTABLE_VARIANCE, "Performance lost detected!");
			if (var < MIN_ACCEPTABLE_VARIANCE) Assert.Inconclusive("Performance was much better than expected.");
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:22,代碼來源:UnitPerformanceTests.cs

示例8: AmountScenario01PerformanceTest

		public void AmountScenario01PerformanceTest()
		{
			Amount distance;
			Amount speed;
			Amount duration = new Amount(0m, TimeUnits.Day);

			long t = Environment.TickCount;
			for (int n = 1; n <= 10000; n++)
			{
				distance = new Amount(50m, new Unit("myfoot", "myft", 44m, LengthUnits.CentiMeter));
				speed = new Amount(n, LengthUnits.KiloMeter / TimeUnits.Hour);
				duration += distance / speed;
			}
			double time = (Environment.TickCount - t) / 1000.0;
			double var = (time - 0.234) / 0.234;

			duration = duration.ConvertedTo(TimeUnits.Minute, 1);
			
			Console.WriteLine("Time to perform 10K complex scenario: {0} sec.", time);
			Console.WriteLine("Variation: {0:0}%.", var * 100);

			Assert.AreEqual(12.9m, duration.Value);
			Assert.IsTrue(duration.Unit.CompatibleTo(TimeUnits.Second));

			Assert.IsTrue(var < MAX_ACCEPTABLE_VARIANCE, "Performance lost detected!");
			if (var < MIN_ACCEPTABLE_VARIANCE) Assert.Inconclusive("Performance was much better than expected.");
		}
開發者ID:codetuner,項目名稱:Arebis.Common,代碼行數:27,代碼來源:UnitPerformanceTests.cs


注:本文中的Amount.ConvertedTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。