private static double _MassOuncesToSI(double value, Unit toUnit) { Debug.Assert(_IsSIUnit(toUnit)); double convertedValue = MassConvertor.OuncesToGrams(value); // [g] if (Unit.Kilogram == toUnit) { convertedValue = MassConvertor.GramsToKilograms(convertedValue); // [kg] } return(convertedValue); }
private static double _ConvertMass(double value, Unit fromUnit, Unit toUnit) { Debug.Assert((Unit.Pound == toUnit) || (Unit.Ounce == toUnit) || (Unit.Kilogram == toUnit) || (Unit.Gram == toUnit)); double convertedValue = value; if (Unit.Ounce == fromUnit) // [oz] { convertedValue = (Unit.Pound == toUnit)? MassConvertor.OuncesToPounds(value) : // [lb] _MassOuncesToSI(value, toUnit); // [g], [kg] } else if (Unit.Pound == fromUnit) // [lb] { convertedValue = MassConvertor.PoundsToOunces(value); // [oz] if (Unit.Ounce != toUnit) { convertedValue = _MassOuncesToSI(convertedValue, toUnit); // [g], [kg] } } else if (Unit.Kilogram == fromUnit) // [kg] { convertedValue = MassConvertor.KilogramsToGrams(value); // [g] if (Unit.Gram != toUnit) { convertedValue = _MassGramsToUS(convertedValue, toUnit); // [oz], [lb] } } else if (Unit.Gram == fromUnit) // [g] { convertedValue = (Unit.Kilogram == toUnit)? MassConvertor.GramsToKilograms(value) : // [kg] _MassGramsToUS(value, toUnit); // [oz], [lb] } return(convertedValue); }