View Single Post
Old 06-25-2019, 07:53 AM   #6
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by BetterRed View Post
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.
davidfor is offline   Reply With Quote