doubleToStringHours method

String doubleToStringHours(
  1. double decimalValue
)

Converts a decimal hour value to a formatted "HH:MM hrs" string.

Takes a decimal representation of hours (e.g., 2.5 for 2 hours 30 minutes) and converts it to a formatted time string with zero-padded hours and minutes.

Parameters:

  • decimalValue: Decimal hours value (e.g., 2.5, 1.75, 8.25)

Returns a formatted string in "HH:MM hrs" format

Example:

final time1 = RtCommonFunction.instance.doubleToStringHours(2.5);
// Returns: "02:30 hrs"

final time2 = RtCommonFunction.instance.doubleToStringHours(1.75);
// Returns: "01:45 hrs"

Implementation

String doubleToStringHours(double decimalValue) {
  int totalMinutes =
      (decimalValue * 60).toInt(); // Convert hours to total minutes
  int hours = totalMinutes ~/ 60; // Get total hours
  int minutes = totalMinutes % 60; // Get remaining minutes

  return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')} hrs'; // Format as "hh:mm"
}