public static double ConvertVolumeToLiters(double volume, FillupUnits unitOfMeasure) { switch (unitOfMeasure) { case FillupUnits.ImperialGallons: return volume * LitersPerImperialGallon; case FillupUnits.UsGallons: return volume * LitersPerUsGallon; case FillupUnits.Litres: return volume; default: throw new ArgumentOutOfRangeException(); } }
public static MvcHtmlString DisplayQuantityFor(this HtmlHelper helper, double quantity, FillupUnits unitOfMeasure) { return MvcHtmlString.Create(FormatQuantityFor(quantity, unitOfMeasure)); }
public static MvcHtmlString DisplayPricePerUnitFor(this HtmlHelper helper, double pricePerUnit, FillupUnits unitOfMeasure) { return MvcHtmlString.Create(FormatPricePerUnitFor(pricePerUnit, unitOfMeasure)); }
public static string FormatQuantityFor(double quantity, FillupUnits unitOfMeasure) { double liters = UnitConversionHelper.ConvertVolumeToLiters(quantity, unitOfMeasure); return string.Format(UnitConversionHelper.UserUnitOfMeasure == FillupUnits.Litres ? "{0:#00.00}{1}" : "{0:#00.000} {1}", UnitConversionHelper.ConvertVolumeToUserUnit(liters), FormatVolumeUnitAbbreviation()); }
public static string FormatPricePerUnitFor(double pricePerUnit, FillupUnits unitOfMeasure) { double pricePerLiter = pricePerUnit/UnitConversionHelper.ConvertVolumeToLiters(1, unitOfMeasure); double pricePerUserUnit = pricePerLiter/UnitConversionHelper.ConvertVolumeToUserUnit(1.0); return string.Format("{0:C2}/{1}", pricePerUserUnit, FormatVolumeUnitAbbreviation(plural: false)); }
public static void SetUnitsForRegion(RegionInfo regionInfo) { var isMetric = regionInfo == null || regionInfo.IsMetric; UserDistanceUnit = isMetric ? DistanceUnits.Kilometer : DistanceUnits.Mile; UserUnitOfMeasure = isMetric ? FillupUnits.Litres : FillupUnits.UsGallons; }