This content has been marked as final.
Show 2 replies
-
1. Re: How to convert minutes to decimal
Carl Von Stetten Jun 30, 2014 9:42 AM (in response to weezerboy)How do I do this?
The simple answer: with math.
Longer answer: parse it using list functions and then do some math. Like this:
<cfset MyTime = "43:15"> <cfset hours = ListFirst(MyTime, ":") > <!--- get the hours part ---> <cfset minutes = ListLast(MyTime, ":") > <!--- get the minutes part ---> <cfset decimalMinutes = minutes / 60 > <!--- Calculate minutes as decimal of an hour ---> <cfset MyDecimalTime = hours + decimalMinutes > <!--- Put it all back together as decimal hours --->
Or, in more terse form:
<cfset MyTime = "43:15"> <cfset MyDecimalTime = ListFirst(MyTime, ":") + (ListLast(MyTime, ":") / 60) >
HTH,
-Carl V.
-
2. Re: How to convert minutes to decimal
BKBK Jul 1, 2014 4:46 AM (in response to weezerboy)If you need to round off to 2 decimals and to pad with 0s, that is, 10.50 instead of 10.5, then adapt Carl's solution to
<cfset MyDecimalTime = numberFormat(ListFirst(MyTime, ":") + (ListLast(MyTime, ":") / 60), "00.00")>



