0

If the value 5.22 equivalent to (5 hours : 13 minutes) when calculated is not an integral multiple of 15 minutes reckoned from the start of an hour, the 5.22 is to be rounded up to the nearest integral multiple of 15 minutes.

Example,

5.22 = 5.25 = equivalent to (5 hours : 15 minutes)

  • 1
    Break it down into steps. How do you get the nearest whole multiplier (hint: division). Then check if there is a remainder and if not increment by 1 (step). – Igor Apr 27 '20 at 11:31
  • Is this what you are looking for https://stackoverflow.com/questions/35955024/round-to-25-50-75-100 ? – Alin Mircea Apr 27 '20 at 11:31
  • Possible duplicate of [Round to 25, 50, 75, 100](https://stackoverflow.com/questions/35955024/round-to-25-50-75-100) – GSerg Apr 27 '20 at 11:35
  • 100 / 60 and simple cross product will give you the convertion from Minute to Numeric. Then you simply have to round up with a ceilling – Drag and Drop Apr 27 '20 at 11:35
  • 1
    Does this answer your question? [Is there a simple function for rounding UP a DateTime to the nearest 15 minutes?](https://stackoverflow.com/questions/7029353/how-can-i-round-up-the-time-to-the-nearest-x-minutes) – Drag and Drop Apr 27 '20 at 11:36
  • And `TimeSpan.FromMinutes(5.22)`, [MSDN](https://learn.microsoft.com/en-us/dotnet/api/system.timespan.fromminutes?view=netcore-3.1). Can help you in the convertion from Decimal to HourMinute. [Convert Decimal to Hours Minutes and Seconds in C# .Net](https://stackoverflow.com/questions/18404243/convert-decimal-to-hours-minutes-and-seconds-in-c-sharp-net/18404284) – Drag and Drop Apr 27 '20 at 11:42
  • math.Floor(value) => returns the largest integer less than or equal to the specified decimal number. Math.Ceiling(value) => returns the smallest integral value is greater than or equals to specified decimal number. – Amin Golmahalleh Apr 27 '20 at 12:08
  • `var time = TimeSpan.FromMinutes(Math.Round(5.22 / 25, 2) * 25);` – Nenad Apr 27 '20 at 12:11
  • thanks for your feedback. I think some not works what if 5.08 it should be converted to 5.15 instead of 5.25 right? – Nung Sabaya Apr 27 '20 at 12:51

0 Answers0