/// <summary> /// Converts a <see cref="double"/> to an SIString, if parameter is a <see cref="string"/> uses it as the unit /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="language"></param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, string language) { if (value is double d) { return(SIHelpers.ToSIStringExcludingSmallPrefixes(d, (parameter as string) ?? string.Empty)); } return(string.Empty); }
/// <summary> /// Converts a number to SIString using <see cref="CSharpEnhanced.Helpers.SIHelpers.ToS"/> /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="language"></param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, string language) { if (MathsHelpers.TryCastToDouble(value, out var result)) { return(_ExcludeSmallPrefixes ? SIHelpers.ToSIStringExcludingSmallPrefixes(result, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName) : SIHelpers.ToSIString(result, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName)); } if (value is Complex c) { return(_ExcludeSmallPrefixes ? SIHelpers.ToAltSIStringExcludingSmallPrefixes(c, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName) : SIHelpers.ToAltSIString(c, _Unit, _RoundToDigit, _MidpointRounding, _UseFullName)); } return(0); }
/// <summary> /// Returns a string for display in component info section which will be in the form: /// "{<paramref name="description"/>}: {<paramref name="value"/>}{<paramref name="unit"/>}" /// If <paramref name="value"/> is a <see cref="double.NaN"/> it is instead displayed as "unavailable" and the unit is omitted /// </summary> /// <param name="description"></param> /// <param name="value"></param> /// <param name="unit"></param> /// <returns></returns> private string LineInfo(string description, double value, string unit) => description + ": " + (double.IsNaN(value) ? "unavailable" : SIHelpers.ToSIStringExcludingSmallPrefixes(value, unit, _RoundToDigit));