View Single Post
Old 07-30-2020, 06:47 AM   #13
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,473
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Multiply by 60 to get the number of minutes.

For 2.29 hours that's ~137 minutes.

Divide that by sixty again using whole numbers and the remainder is 17 minutes.

You end up with 2:17.
Unfortunately you currently can't do that calculation in the template language. All the arithmetic is floating point.

I am going to add some more math functions: floor(x), ceiling(x), fractional_part(x), round(x), and mod(x, y). Using these (when they are released), you will be able to compute hours:minutes from fractional hours using something like this template.
Code:
program:
# total_hours should be a field reference
	fractional_hours = 3.6982;
# Compute the number of hours in total minutes as an integer
	display_hours = floor(fractional_hours );
# Compute the number of minutes left over after display_hours
	display_mins = round(multiply(fractional_part(fractional_hours ), 60));
# Format the results as h:mm
	strcat(display_hours, ':', format_number(display_mins, '02d'))
This template produces the result "3:42"
chaley is offline   Reply With Quote