Quote:
Originally Posted by BetterRed
Hopefully one of the template experts, such as chaley, davidfor will chime in.
|
And personally, I hope chaley comes along first
But...
If it isn't obvious, I usually do it in program mode first. This is what I got:
Code:
program:
pages = cmp(raw_field('#pages'),0,1,1,raw_field('#pages'));
words = cmp(raw_field('#pages'),0,0,0,raw_field('#words'));
divide(words,pages);
The idea is to get a non-zero number for the page count no matter what, and use zero for th word count if the page count was supposed to be zero. That gives zero for the words per page if there are no pages. But, maybe it should be the word count or something else.
In non-program mode this becomes:
Code:
{:'divide(cmp(raw_field("#pages"),0,0,0,raw_field("#words")),cmp(raw_field("#pages"),0,1,1,raw_field("#pages")))'}
And for the record, the first attempt was:
Code:
{#pages:'test($,divide(raw_field("#words"),raw_field("#pages")),0)'}
But, the "divide" is always executed even if the the first value is empty. I wasn't expecting that.
To get an integer, you can use "format_number" with an appropriate format template.