Converting number or decimal ratio into hours and minutes

I have been trying all day to get this to work and I found out that Integer typecasting was resulting in the math chewing the final total 1 quantity short on both hours and minutes.

Here is the corrected code that is now working for me to calculate a basic ratio of minutes-to-sixty and showing the end result in hours and minutes.

If t_decimal.Text = "" Then
  t_decimal.Text = "0"
  t_minutes.Text = "0"
  t_hours.Text = "0"
End If

Var c_decimal As Double
Var c_hours As Integer
Var c_minutes As Double

c_hours = 0
c_minutes = 0

c_decimal = Val(t_decimal.Text)

While c_decimal >= 1
  c_hours = c_hours + 1
  c_decimal = c_decimal - 1

c_minutes = c_decimal * 60

t_hours.Text = Str(c_hours)
t_minutes.Text = c_minutes.ToString(Locale.Current, "###.#")

I hope this helps other people.

Below is a screen grab.

You can download my window exported for integration into desktop apps.

The code is basic math, and you can try it in Android or iOS apps, too.


May I ask, what is the use case? I haven’t encounter this yet.

1 Like

Here is one use case, and I actively use this for my own billing:

If you are a professional who has to record worked, billable, and invoiced hours – like me – the convenience of a converter saves me so much effort when I am drafting my invoices. A lot of professionals like attorneys may adjust their billing to meet contractual minimums, and it is easier with a converter.

If anyone on here is working on billing / payroll / project management software, this is a use case.

Interesting. We bill by the quarter hour. I can literally bill 3 clients 0.25 hours in the course of a half hour. I enter a fractional amount and then just add them up and multiply by the hourly rate when we generate invoices.

1 Like

If you work in the legal industry, high rates have resulted in minimums of a tenth of an hour and sometimes as little as five percent of an hour.

When you’re forking over $1k+ per hour, a quarter-hour minimum would be very difficult for non-wealthy clients to pay for. So it is not uncommon for my billing sheets to show three minutes on one task (e.g. an e-mail response or a scan-and-file task).

So the chart is literally a necessity on the window, for easy reference. The calculator / converter function is something that I am porting to Android for use in a matters manager for attorneys doing “road work” such as visiting clients at a jail or attending a deposition.

Law firms have such a unique set of requirements that many billing / tracking / project management apps currently on the market have serious deficiencies that leave attorneys frustrated and sticking to their use of paper-based recordkeeping.

I work at multiple law firms so I have an “unfair” advantage as a software developer targeting this market.

1 Like