T K T K - 4 days ago 5
Javascript Question

Convert final two digits to a percent value over 60. (e.g., 15 / 60 => .25 etc)

I have given numbers like these:


0915

0930

0945

1000

0015



They should be rounded and look like this:



0900 => 9

0915 => 9.25

0930 => 9.5

0945 => 9.75

1000 => 10

0015 => 0.25



I tried a lot of functions like round and ceil but i cant get it working. It is for a calendar, the given numbers are the times where the meetings start like '09:45'.

Answer
(n.substr(0,2))*1 + n.substr(2,2)/60

will give you the expected result

where n is a string representing time in the format HHmm where HH is the hour, mm minutes as in the data you posted as example. Both value must be two digits numbers forming a 4 digits string.

Comments