当前位置: 首页>>代码示例>>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;未经允许,请勿转载。