Example #1
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="units">The units.</param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public static string ToString <TSelf>(this IMeasurement <TSelf> measurement, Unit <TSelf> unit1, params Unit <TSelf>[] units)
            where TSelf : IMeasurement <TSelf>
        {
            Validate.NonNull(measurement, nameof(measurement));
            Validate.NonNull(unit1, nameof(unit1));
            Validate.NonNull(units, nameof(units));

            units = units.Concat(new[] { unit1 }).OrderBy(x => measurement.ToDouble(x)).ToArray();
            var unit = units.FirstOrDefault(x => measurement.ToDouble(x) >= 1) ??
                       units.FirstOrDefault() ??
                       measurement.MeasurementProvider.ParsableUnits.FirstOrDefault() ??
                       measurement.MeasurementProvider.DefaultUnit;

            return(measurement.ToString(unit, "0.##"));
        }