View Single Post
Old 01-23-2016, 03:23 PM   #28
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,499
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by fogice View Post
Does format_number return a text value or a numerical value? I'm kind of confused about that, because it looks like text, but then we use cmp on its outputs, which looks like it would require a number.
( edit ) Nevermind, cmp converts to integer to make the comparison.
All template language functions return strings.

The cmp function converts its input to float before comparing the values.
Quote:
I also don't understand how strcat doesn't always include a non-null value for final_sidx, even when sidx is null.
format_number returns the empty string (not the null string) if the input value is empty. finish_formatting returns the empty string if the input value is empty. Thus
Code:
sidx=field('series_index');
i=format_number(sidx, "{:02d}");
f=format_number(sidx, "{:04.1f}");
isInt=cmp(f, i, '', 'yes', '');
final_sidx=finish_formatting(
    test(isInt, i, f),
    '',
    ' ',    <---- There is a space between the single quotes
    ' '     <---- There is a space between the single quotes
);
returns the empty string if sidx is empty. strcat is happy to concatenate the empty string, which of course does not change the result at all.
chaley is offline   Reply With Quote