From Decimal to 'hh:mm:ss' Conversion

LdR
Tera Expert

Hi,

Is it possible to convert a decimal field (representing hours) into the 'hh: ss' format?
Example:
1.5 h → 1h 30 minutes

Thank you.

1 ACCEPTED SOLUTION

ARG645
Tera Guru

Things to consider: 

input parameter cannot be less than Zero as you are converting the Decimal hh:mm:ss format.

decimalTohhmmss(1.5); //will give you 01:30:00
decimalTohhmmss(0.5); //will give you 00:30:00
decimalTohhmmss(-1.0); //Will give nothing

function decimalTohhmmss(decimal){
	if(decimal< 0) // return nothing if the parameter is negative
	return;
	var totalSeconds = decimal*3600;
	var hours   = Math.floor(totalSeconds / 3600);
	var minutes = Math.floor((totalSeconds - (hours * 3600)) / 60);
	var seconds = totalSeconds - (hours * 3600) - (minutes * 60);
			
	// round seconds
	seconds = Math.round(seconds * 100) / 100;
			
	var result = (hours < 10 ? "0" + hours : hours);
	result += ":" + (minutes < 10 ? "0" + minutes : minutes);
	result += ":" + (seconds  < 10 ? "0" + seconds : seconds);
	return result;
};

View solution in original post

5 REPLIES 5

Nisha6
Kilo Explorer

Hi Everyone,

 

I have a similar requirement but not able to achieve it can anyone please help on this?

Requirement : - Based on Worked Hours (type - decimal) the Time worked should populate.

 

find_real_file.png

 

Thanks and Regards,

Nisha