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

0

I needed to create a function that received two hours in the format (00:00:00), calculates the number of hours between them, and converts 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
    
asked by anonymous 13.05.2016 / 19:16

1 answer

3

There is a concept problem, in case 2 hours and 30 minutes should floating point be represented as 2.50 this because 1 hour which in the case is evaluated as 1.0 floating point are 60 minutes, starting from this principle 30 minutes should equivalent to 0.5 being thus 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) simply convert the period in minutes.

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

in rule 3

The ratio 1 to 60, ie 1 in floating point equals sixty minutes and obtain the floating point value equivalent to the one to be converted (150 minutes) considering the established ratio, thus obtaining the expression below

60X = 150*1 ==> X = 150/60 ==> X = 2,50
    
13.05.2016 / 19:41