-
Jul 22nd, 2018, 08:08 AM
#1
Thread Starter
Enjoy the moment
[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
-
Jul 22nd, 2018, 08:15 AM
#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.
-
Jul 22nd, 2018, 08:36 AM
#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
-
Jul 22nd, 2018, 08:50 AM
#4
Thread Starter
Enjoy the moment
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
-
Jul 22nd, 2018, 09:01 AM
#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
-
Jul 22nd, 2018, 09:02 AM
#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.
-
Jul 22nd, 2018, 09:08 AM
#7
Thread Starter
Enjoy the moment
Re: trying to convert minutes to hours disnt calculate right why?
so i do i calculate 30 + 15+ 60? 1.75?
-
Jul 22nd, 2018, 09:39 AM
#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
-
Jul 22nd, 2018, 09:56 AM
#9
Thread Starter
Enjoy the moment
Re: trying to convert minutes to hours disnt calculate right why?
it doesn't make any sense Lavolpe sir
-
Jul 22nd, 2018, 10:11 AM
#10
Thread Starter
Enjoy the moment
Re: trying to convert minutes to hours disnt calculate right why?
got it now sir Lavolpe thank you
tnx Sami
-
Jul 22nd, 2018, 10:11 AM
#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).
Edited: We posted at same time. Ignore this reply if you have your answer.
-
Jul 22nd, 2018, 10:12 AM
#12
Thread Starter
Enjoy the moment
Re: [RESOLVED] trying to convert minutes to hours disnt calculate right why?
got it now sir Lavolpe thank you
-
Jul 22nd, 2018, 10:30 AM
#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
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jul 22nd, 2018, 10:44 AM
#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.
-
Jul 22nd, 2018, 12:17 PM
#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
Private Sub Form_Load()
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
Last edited by ChrisE; Jul 22nd, 2018 at 12:24 PM.
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|