View Single Post
Old 07-30-2020, 01:52 PM   #18
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,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by davidfor View Post
And here was me thinking of doing:

Code:
program:
minutes = divide(raw_field('#words'),310);
hours = divide(minutes, 60);
hours = list_item(hours,0,'.');
minutes = subtract(minutes, multiply(hours,60));
minutes = format_number(minutes, '02,.0f');
strcat(hours,':',minutes)
Ugly, but it seems to work. I'd probably combine a couple of lines, but, separating them helps the debugging.

But, I've wanted some of your new functions before. So, I'm happy to see them.
This is a very interesting use of list_item. Cool. It got me thinking about other unusual ways to solve the problem using the period as a separator. I came up with this
Code:
program:
	fractional_hours = 3.6982;
	re_group(
		fractional_hours,
		'(.*)(\..*)',
		'{$}:', 
		"program: format_number(multiply($, 60), '02.0f')"
	)
This works as long as there really is a period in the number.

Last edited by chaley; 07-30-2020 at 01:54 PM.
chaley is offline   Reply With Quote