View Single Post
Old 06-25-2019, 06:12 AM   #3
Soap-dodger
Member
Soap-dodger began at the beginning.
 
Soap-dodger's Avatar
 
Posts: 14
Karma: 10
Join Date: Dec 2016
Location: United Kingdom
Device: Amazon Kindle PaperWhite 3
Quote:
Originally Posted by BetterRed View Post
See Arithmetic functions in Template language - Function classification

BR
Thanks for the link. I did have a look there and it did help somewhat.

I have almost got this working now, though I still have a couple of issues to iron out, and any help you might offer will be appreciated.

First, in order to ensure that I do not attempt the division if either #words or #pages have null or zero values, I first created a temporary custom column called #ready, which has the following template:

Code:
{:'and(field('#words'), strcmp(field('#words'), "", "", "", cmp(field('#words'), 0, "", "", field('#words'))), field('#pages'), strcmp(field('#pages'), "", "", "", cmp(field('#pages'), 0, "", "", field('#pages'))))'}
This seems to work perfectly, returning a "1" only when the division makes sense, else it is empty.

Using #ready as a base, I then created another custom field to carry out the division and called it #awp (average words per page). This field has the template:

Code:
{:'test(and(field('#words'), strcmp(field('#words'), "", "", "", cmp(field('#words'), 0, "", "", field('#words'))), field('#pages'), strcmp(field('#pages'), "", "", "", cmp(field('#pages'), 0, "", "", field('#pages')))), divide(field('#words'), field('#pages')), "")'}
Apart from one use case, this works, returning a floating point value. I need to work out how to round the returned value to a whole number, though.

The only time it doesn't work is when both #words and #pages contain null values. In this case, I get the following error message:

Code:
EXCEPTION:  float division by zero
Can you help solve these issues?
Soap-dodger is offline   Reply With Quote