Introduction
This is a very simple code to show how we can calculate the round time in C# .NET...
Using the Code
You can write the below code in your Windows application form_load
method and test it...
TimeSpan t = new TimeSpan(1, 7, 0);
int Round = 15;
double CountRound = (t.TotalMinutes / Round);
int Min = (int)Math.Truncate(CountRound + 0.5) * Round;
TimeSpan tRes = new TimeSpan(0, Min, 0);
MessageBox.Show(tRes.ToString());
You can change the Round number from 15 to every number you want round on, for example 5 or 10 or ...
Good luck!
History
- 23rd January, 2007: Initial post