Beispiel #1
0
 /// <summary>
 /// Converts kilograms to kg or pound depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="kiloGrams">The amount of weight.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <exception cref="CultureNotFoundException">Is thrown if the <paramref name="localeId"/> is not a valid culture.</exception>
 /// <returns>The converted amount of weight.</returns>
 public static double GetWeight(string localeId, double kiloGrams)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     if (Math.Abs(kiloGrams) < CompareTolerance)
     {
         return(0);
     }
     return(GetRegion(localeId).IsMetric ? kiloGrams : UnitConversionCalculator.ConvertKilogramToPounds(kiloGrams));
 }
Beispiel #2
0
 /// <summary>
 /// Converts meters to m or ft depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="meters">The amount of altitude.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <returns>The converted amount of altitude.</returns>
 public static double GetAltitude(string localeId, double meters)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     if (Math.Abs(meters) < CompareTolerance)
     {
         return(meters);
     }
     return(GetRegion(localeId).IsMetric ? meters : UnitConversionCalculator.ConvertMetersToFeet(meters));
 }
Beispiel #3
0
 /// <summary>
 /// Converts meters/s to km/h or miles/h depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="metersPerSecond">The amount of speed.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <returns>The converted amount of speed.</returns>
 public static double GetSpeed(string localeId, double metersPerSecond)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     if (Math.Abs(metersPerSecond) < CompareTolerance)
     {
         return(0);
     }
     return(GetRegion(localeId).IsMetric
         ? UnitConversionCalculator.ConvertMetersPerSecondToKilometersPerHour(metersPerSecond)
         : UnitConversionCalculator.ConvertMetersPerSecondToMilesPerHour(metersPerSecond));
 }
Beispiel #4
0
 /// <summary>
 /// Converts meters to km or miles depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="meters">The amount of distance.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <returns>The converted amount of distance.</returns>
 public static double GetDistance(string localeId, double meters)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     if (Math.Abs(meters) < CompareTolerance)
     {
         return(meters);
     }
     return(GetRegion(localeId).IsMetric ? meters * Constants.KilometersPerMeter : UnitConversionCalculator.ConvertMetersToMiles(meters));
 }
Beispiel #5
0
 /// <summary>
 /// Converts meters to km or yards depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="meters">The amount of distance.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <returns>The converted amount of distance.</returns>
 public static double GetSmallDistance(string localeId, double meters)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     return(GetRegion(localeId).IsMetric ? meters : UnitConversionCalculator.ConvertMetersToYards(meters));
 }
Beispiel #6
0
 /// <summary>
 /// Converts centimeters to cm or inch depending on the <paramref name="localeId" />.
 /// </summary>
 /// <param name="localeId">The locale ID.</param>
 /// <param name="centiMeters">The amount of height.</param>
 /// <exception cref="ArgumentNullException">Is thrown if <paramref name="localeId"/> is <c>null</c> or empty.</exception>
 /// <returns>The converted amount of height.</returns>
 public static double GetHeight(string localeId, double centiMeters)
 {
     CheckUtil.ThrowIfNullOrEmpty(() => localeId);
     return(GetRegion(localeId).IsMetric ? centiMeters : UnitConversionCalculator.ConvertCentimetersToInches(centiMeters));
 }