How to convert Time into decimal float in Google Sheets using Script?

Just Multiply your Duration by 24.

Example:

Time In     | Time out   | Duration | Decimal
11:45:00 AM | 3:40:00 PM | 3:55:00  | 3.92

You also have to alter the format of the cell containing the decimal from Automatic to Number in order for this to work in Google Sheets.


Google Sheets

In Google Sheets, if you have a date/time value in a cell (e.g. "D9"), then use =HOUR(D9)+(MINUTE(D9)/60).

If the value is stored in the format 04:29, then use =INDEX(SPLIT(D9, ":"), 1) + (INDEX(SPLIT(D9, ":"), 2)/60).


Google Sheets API & Google Apps Script

If you want to use the Google Sheets API or Google Apps Script, then you can use javascript.

You need to use the getMinutes() method and divide by 60, then add that to the hour (using getHours()).

var date = new Date();
var minutes = date.getMinutes();
var output = date.getHours() + (minutes/60);

Be aware that this is ignoring seconds.

If the value in the cell is stored as a string like 04:29, then you'll need to split it.

var time = "04:29";
var hour = Number(time.split(":")[0]);
var minutes = Number(time.split(":")[1]);
var output = hour + (minutes/60);

All you need is TO_PURE_NUMBER()
https://support.google.com/docs/answer/3094243?hl=en

Example:

// The following
A1=DATEVALUE("2020-05-18 06:09:18.821 ")+TIMEVALUE("2020-05-18 06:09:18.821 ")
A2=TO_PURE_NUMBER(A1)
A3=TO_DATE(A2)

// Results in the following, first result is just a formatted date
2020-05-18 6:09:19
43969.25647
5/18/2020