public ITicksInfo <int> GetTicks(Range <int> range, int ticksCount) { double start = range.Min; double finish = range.Max; double delta = finish - start; int log = (int)Math.Round(Math.Log10(delta)); double newStart = RoundHelper.Round(start, log); double newFinish = RoundHelper.Round(finish, log); if (newStart == newFinish) { log--; newStart = RoundHelper.Round(start, log); newFinish = RoundHelper.Round(finish, log); } // calculating step between ticks double unroundedStep = (newFinish - newStart) / ticksCount; int stepLog = log; // trying to round step int step = (int)RoundHelper.Round(unroundedStep, stepLog); if (step == 0) { stepLog--; step = (int)RoundHelper.Round(unroundedStep, stepLog); if (step == 0) { // step will not be rounded if attempts to be rounded to zero. step = (int)unroundedStep; } } if (step < minStep) { step = minStep; } if (step > maxStep) { step = maxStep; } if (step <= 0) { step = 1; } int[] ticks = CreateTicks(start, finish, step); TicksInfo <int> res = new TicksInfo <int> { Info = log, Ticks = ticks }; return(res); }
public void SetNewTimerInterval() { int interval = new DbHelper().SelectNextInterval(); if (interval < 0) { interval = m_sleepTick; } if (interval == 0) { interval = 1; } m_log.DebugFormat("Picked new timer interval which is {0} ms ({1} min.)", interval, RoundHelper.Round(interval / 1000.0m / 60.0m, 2)); m_timer.Interval = interval; }
public string FormatNextTaskRemindingDate() { int maxTimeTextLength = 38; // Text length without task description int maxLength = 64; // for NotifyIcon.Text property it's maximum int maxTaskNameLength = maxLength - maxTimeTextLength; string text = "Nothing to be mindered about"; Task nextTask = new DbHelper().NextTaskToShow(); if (nextTask == null) { return(text); } if (string.IsNullOrEmpty(nextTask.Text) == false && nextTask.Text.Length > maxTaskNameLength) { nextTask.Text = nextTask.Text.Substring(0, maxTaskNameLength); } DateTime?nextDate = nextTask.DateRemainder; if (nextDate.HasValue == false) { return(text); } text = string.Format("Task {0} minders at {1}", nextTask.Text, DBTypesConverter.ToFullDateStringByCultureInfo(nextDate.Value)); TimeSpan difference = nextDate.Value.Subtract(DateTime.Now); decimal days = RoundHelper.Round((decimal)difference.TotalDays, 0); if (days < 1) { text = string.Format("Task {0} minders at {1}", nextTask.Text, nextDate.Value.ToShortTimeString()); } decimal minutes = RoundHelper.Round((decimal)difference.TotalMinutes, 0); if (difference.TotalHours < 1) { text = string.Format("Task {0} minders in {1} minutes", nextTask.Text, minutes); } if (minutes < 1) { text = (string.Format("Task {0} minders in less than a minute", nextTask.Text)); } return(text); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int val = System.Convert.ToInt32(value); return((int)(RoundHelper.Round(val) / Factor)); }
public static decimal Round(decimal val) { return(RoundHelper.Round(val, 10)); }