private string FormatDouble(MailTagTypes type, string param) { double value = _factory.GetDoubleValue(type); SIUnitTypes unit = ProgramSettings.Instance.ShowUnitType; Match paramMatch = Regex.Match(param, METHOD_PARAM, RegexOptions.IgnoreCase); while (paramMatch.Success) { if (paramMatch.Groups["method"].Value.ToUpper() == "ROUND") { value = System.Math.Round(value, Int32.Parse(paramMatch.Groups["param"].Value)); } else if (paramMatch.Groups["method"].Value.ToUpper() == "UNIT") { switch (paramMatch.Groups["param"].Value.ToUpper()) { case "G": unit = SIUnitTypes.Go; break; case "M": unit = SIUnitTypes.Mo; break; case "K": unit = SIUnitTypes.ko; break; } } paramMatch = paramMatch.NextMatch(); } return(UnitsConverter.SIUnitToString(value, unit)); }
public static double ConvertKo(double value, SIUnitTypes convert) { switch (convert) { case SIUnitTypes.Mo: return(value / 1024); case SIUnitTypes.Go: return(value / 1048576); default: return(value); } }
public static string SIUnitToString(double value, SIUnitTypes convert) { switch (convert) { case SIUnitTypes.Mo: return(String.Format("{0:N2} Mo", (double)value / 1024)); case SIUnitTypes.Go: return(String.Format("{0:N2} Go", (double)value / 1048576)); default: return(String.Format("{0:N2} ko", (double)value)); } }