public static String ToString(Double value, SIUnit unit, String format, IFormatProvider formatProvider) { var unitStr = unit.Symbol; if (value != 0) { var scale = 0; var log10 = Math.Log10(value); if (log10 < 0) { value = MakeLarger(value, unit, out scale); } else if (log10 > 0) { value = MakeSmaller(value, unit, out scale); } if (scale != 0) { unitStr = Prefixes[scale].Symbol + unit.Symbol; } } return String.Format(formatProvider, "{0} {1}", value, unitStr); }
public static String ToString(Double value, SIUnit unit, String format, IFormatProvider formatProvider) { var unitStr = unit.Symbol; if (value != 0) { var scale = 0; var log10 = Math.Log10(value); if (log10 < 0) { value = MakeLarger(value, unit, out scale); } else if (log10 > 0) { value = MakeSmaller(value, unit, out scale); } if (scale != 0) { unitStr = Prefixes[scale].Symbol + unit.Symbol; } } return(String.Format(formatProvider, "{0} {1}", value, unitStr)); }
private static Double MakeLarger(Double value, SIUnit unit, out Int32 scale) { var result = value; scale = 0; foreach (var prefix in unit.NegativePrefixes) { if (Math.Log10(result) >= 0) { return result; } result = Math.Pow(10, -prefix) * value; scale = prefix; } return result; }
private static Double MakeLarger(Double value, SIUnit unit, out Int32 scale) { var result = value; scale = 0; foreach (var prefix in unit.NegativePrefixes) { if (Math.Log10(result) >= 0) { return(result); } result = Math.Pow(10, -prefix) * value; scale = prefix; } return(result); }
private static Double MakeSmaller(Double value, SIUnit unit, out Int32 scale) { var result = value; scale = 0; foreach (var prefix in unit.PositivePrefixes) { var log10 = Math.Log10(result); if ((log10 <= 2) || (log10 < prefix)) { return result; } result = Math.Pow(10, -prefix) * value; scale = prefix; } return result; }
private static Double MakeSmaller(Double value, SIUnit unit, out Int32 scale) { var result = value; scale = 0; foreach (var prefix in unit.PositivePrefixes) { var log10 = Math.Log10(result); if ((log10 <= 2) || (log10 < prefix)) { return(result); } result = Math.Pow(10, -prefix) * value; scale = prefix; } return(result); }