View Single Post
Old 10-30-2021, 02:18 PM   #4
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,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by thiago.eec View Post
Code:
program:
	reading_time = divide(raw_field('#mots'), 50);
	h = format_number(subtract(reading_time, fractional_part(reading_time)),  '{0:0>2.0f}');
	m = format_number(multiply(fractional_part(reading_time), 60), '{0:0>2.0f}');
	reading_time = strcat(h, 'h ', m, 'm')
And just for fun, using the recent changes to the template language:
Code:
program:
	reading_time = (if $$#mots == 'none' then 0 else $$#myfloat fi) / 50;
	h = format_number(floor(reading_time), '{0:0>2.0f}');
	m = format_number(fractional_part(reading_time) * 60, '{0:0>2.0f}');
	reading_time = strcat(h, 'h ', m, 'm')
The strange 'if' on line 2 is there because I found a bug in calculating binary operators like '/'. Undefined raw fields don't work. I will fix that. After I fix it the line would be
Code:
	reading_time = $$#mots / 50;
chaley is offline   Reply With Quote