Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 05:45 AM
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.
Solved! Go to Solution.
Labels:
- Labels:
-
Scoped App Development
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2018 03:05 PM
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;
};
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2021 05:58 AM