Calculate the number of hours between two hours and turn into float

Asked

Viewed 1,020 times

0

I needed to create a function that received two hours in the format (00:00:00), calculate the number of hours between them, and convert me to float.

However the float would be of this genre:

Resultado: 2 horas e 30 min -> 2,30
Resultado: 3 horas e 45 min -> 3,45
Resultado: 3 horas e 1 min -> 3,01
resultado: 3 horas e 59 min -> 3,59
  • And how many seconds, how would format?

1 answer

3


There is a concept problem, in case 2 hours and 30 minutes floating point should be represented as 2.50 this because 1 hour which in case is evaluated as 1.0 floating point is 60 minutes, starting from this 30 minutes principle should equal 0.5 and thus 2 hours and 30 minutes ==> 2.50 and not 2.30 as pointed out above!

using 3 rule you convert based on minutes (if the accuracy is in minutes) just convert the period into minutes.

02:30 (two hours and thirty minutes) ==> 150 minutes

in rule of 3

the ratio 1 to 60, that is, 1 in floating point is 60 minutes and obtain the value in floating point equivalent to what one wants to convert (150 minutes) considering the established proportion, thus obtaining the expression below

60X = 150*1 ==> X = 150/60 ==> X = 2,50

Browser other questions tagged

You are not signed in. Login or sign up in order to post.