本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例5: Convert
public Amount Convert(Amount amount)
{
return this.conversionFunction(amount.ConvertedTo(from));
}
示例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.");
}
示例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.");
}
示例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.");
}