예제 #1
0
        public string ToString(DistanceFormat format)
        {
            if (!IsSpecified)
            {
                return(string.Empty);
            }
            switch (format)
            {
            case DistanceFormat.Default:
            case DistanceFormat.DecimalFeet:
                return(string.Format("{0:0.0}'", Feet));

            case DistanceFormat.DecimalInches:
                return(string.Format("{0:0}''", Inches));

            case DistanceFormat.DecimalMeters:
                return(string.Format("{0:0.00} m", Meters));

            case DistanceFormat.DecimalYards:
                return(string.Format("{0:0.00} yd", Yards));

            case DistanceFormat.FeetDecimalInches:
                if (RemainderInches == 0f)
                {
                    return(string.Format("{0:0}'", WholeFeet, RemainderInches));
                }
                return(string.Format("{0:0}' {1:0}''", WholeFeet, RemainderInches));

            case DistanceFormat.DecimalCentimeters:
                return(string.Format("{0:0} cm", Centimeters));

            default:
                return(RawValue);
            }
        }
예제 #2
0
        public static double ToDistanceInRightUnit(this double distanceInMeters, DistanceFormat settingsDistanceFormat)
        {
            double result       = 0;
            double distanceInKm = distanceInMeters / 1000;

            switch (settingsDistanceFormat)
            {
            case DistanceFormat.Mile:
                result = Math.Round(distanceInKm / 1.609344, 1);
                break;

            case DistanceFormat.Km:
                result = Math.Round(distanceInKm, 1);
                break;

            default:
                result = Math.Round(distanceInKm, 1);
                break;
            }

            return(result);
        }