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

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
Author: rray, 2016-05-13

1 answers

There is a problem of concept, in the case 2 hours and 30 minutes should in floating point be represented as 2,50 this because 1 hour that in the case is evaluated as 1.0 in floating point are 60 minutes, starting from this principle 30 minutes should equal 0.5 so 2 hours and 30 minutes = = > 2,50 and not 2,30 as pointed out above!

Using rule of 3 you convert based on minutes (if accuracy is in minutes) just convert the period to minutes.

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

In the rule of 3

The ratio 1 to 60, i.e. 1 at floating point equals sixty minutes and obtain the floating point value equivalent to what you want to convert (150 minutes) considering the established ratio, thus obtaining the expression below

60X = 150*1 ==> X = 150/60 ==> X = 2,50
 3
Author: Aloiso Gomes, 2016-05-13 17:41:16