 # Thread: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

1. ## [RESOLVED] trying to convert minutes to hours disnt calculate right why?

hey,
i have some minutes that i want to calculate to hours
but it shows me the wrong calculation why?

salsa 45 minutes
danny 45 minutes
total in hours 1.30 Hours
but in my code it shows me 1.50
Code:
`FormatNumber(TotalHours / 60, 2, vbTrue)`
tnx for any help
salsa   Reply With Quote

2. ## Re: trying to convert minutes to hours disnt calculate right why?

45 minutes plus 45 minutes IS 1.5 hours, that is, 1 hour and 30 minutes. It is calculating correctly.  Reply With Quote

3. ## Re: trying to convert minutes to hours disnt calculate right why?

Example:

text1 has 45 minutes, text2 has 45 minutes

Code:
```Private Sub Command1_Click()    Dim TotalHours As Double
TotalHours = CDbl(Text1.Text) + CDbl(Text2.Text)
Text3.Text = FormatNumber(TotalHours / 60, 2, vbTrue)
End Sub```  Reply With Quote

4. ## Re: trying to convert minutes to hours disnt calculate right why? Originally Posted by SamOscarBrown 45 minutes plus 45 minutes IS 1.5 hours, that is, 1 hour and 30 minutes. It is calculating correctly.
45 minutes and 45 minutes is 1.30 not 1.50 its a hour and a half  Reply With Quote

5. ## Re: trying to convert minutes to hours disnt calculate right why?

1.3 hours is 78 minutes. 1.5 hours is 90 minutes. 45 plus 45 equals 90...hence, 1.5 hours (90) minutes is correct.

If you had 45 minutes plus 33 minutes (total-78 minutes), the result would be 1.3.

45 minutes and 45 minutes is NOT 1.30...it is 1.50!

You're thinking is not quite right.

Sammi  Reply With Quote

6. ## Re: trying to convert minutes to hours disnt calculate right why?

If you're thinking 1.3 means 1 hour and 30 minutes, you're incorrect.  Reply With Quote

7. ## Re: trying to convert minutes to hours disnt calculate right why?

so i do i calculate 30 + 15+ 60? 1.75?  Reply With Quote

8. ## Re: trying to convert minutes to hours disnt calculate right why? Originally Posted by salsa31 so i do i calculate 30 + 15+ 60? 1.75?
Yes. 1 hour and 45 minutes is same as 1.75 hours. Add up your total minutes and then divide by 60

In your original post, when you were saying that you expected 1.30 instead of 1.5, the 1.3 could better be expressed as hours & minutes

Example: 45 mins + 45 mins = 1 hr 30 mins: Format(Dateadd("n", 45+45,0),"h.n") = 1.3
Example: 45 mins + 45 mins = 1.5 hours: (45+45)/60 = 1.5  Reply With Quote

9. ## Re: trying to convert minutes to hours disnt calculate right why?

it doesn't make any sense Lavolpe sir   Reply With Quote

10. ## Re: trying to convert minutes to hours disnt calculate right why?

got it now sir Lavolpe thank you
tnx Sami   Reply With Quote

11. ## Re: trying to convert minutes to hours disnt calculate right why? Originally Posted by salsa31 it doesn't make any sense Lavolpe sir Sorry, your question doesn't make a lot of sense to us which is why we are a bit confused.

Either you want to display your totals as: a) fractions of hours or b) hours and minutes. 90 minutes = 1 hr 30 mins or 1.5 hours. Anyone seeing a value of "1.3 hours" does not naturally interpret that value as 1 hour and 30 minutes, they would interpret it as 1 hour plus 1/3 of an hour (1 hour and 20 minutes).  Reply With Quote

12. ## Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

got it now sir Lavolpe thank you  Reply With Quote

13. ## Re: trying to convert minutes to hours disnt calculate right why? Originally Posted by LaVolpe Anyone seeing a value of "1.3 hours" does not naturally interpret that value as 1 hour and 30 minutes, they would interpret it as 1 hour plus 1/3 of an hour (1 hour and 20 minutes).
Sorry, I can't resist. Personally, I'd interpret 1.3 hours as 1 hour and 3/10ths of an hour. Or, 1 hour and 18 minutes. Or 1:18. Y'all Take Care,
Elroy  Reply With Quote

14. ## Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

Of course, I was using simple rounding in my old head: a third-ish (0.3) of an hour is easier to mentally calculate than 60*.3 -- don't work harder than I need to.  Reply With Quote

15. ## Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?

Hi salsa,

I prefer working with minutes, but in some will want Decimal.

here a sample for both ways....
Code:
```Private IsModeDecimal As Boolean

Public Function isDecimal() As Boolean
isDecimal = IsModeDecimal
End Function

Private Sub Command1_Click()
Text2.Text = MinutenToZeit(Text1.Text, False)

IsModeDecimal = Text1.Text '
Text3.Text = MinutenToZeit(Text1.Text, IsModeDecimal, 1)
End Sub

Text1.Text = 78
End Sub

Public Function MinutenToZeit(Minuten As Long, IsModeDecimal As Boolean, _
Optional LenghtStunden As Long = 2) As String
'rechnet Minuten um in ZeitString

Dim S() As String
Dim Std As String

Std = String\$(LenghtStunden, "0")
ReDim S(1)
If Not isDecimal Then
S(0) = Format(Minuten \ 60, Std)
S(1) = Format(Minuten Mod 60, "00")
MinutenToZeit = Join(S(), ":")
Else
S(0) = Format(Minuten \ 60, Std)
S(1) = Format(((Minuten Mod 60) * 100) / 60, "00")
MinutenToZeit = Join(S(), ",")
End If
End Function```
regards
Chris  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured