Quantcast
Channel: MobileRead Forums - Calibre
Viewing all articles
Browse latest Browse all 31491

need help with nested template

$
0
0
I've been scouring the reference for functions and the template page in the calibre manual, but there is no example that shows how each term works so I am having trouble understanding it.

I wanted to have a column that would tell me the average words per chapter of each book, so I created a custom column that is built from other columns. I already had a custom column for words and one for chapters.

First I tried this code and received this exception:

Code:

program:divide('#words', '#chapters')

EXCEPTION:  could not convert string to float: #words

Even though both custom columns #words and #chapters are integers, it seems that it is being read as a string.

Here is my next attempt:
Code:

program:
    format_number('#words','{0:d}');
    format_number('#chapters','{0:d}')

While that seemed to be fine, it did not produce any numbers in the column. When I added the divide function, I received the same exception as the first code.

I then tried to combine the divide and format number function together:

Code:

program:divide(format_number('#words','{0:d}'),format_number('#chapters','{0:d}'))

EXCEPTION:  float division by zero

I think that the last one is probably what I want to use. It seems that it is having a problem when it divides by zero, but I am unsure how to fix this.

If I use the second and first code, I would need to assign the result from the format number functions to a variable in order to use the divide function, but I am unsure how to do so.

Any suggestions on how I should change my code?

Viewing all articles
Browse latest Browse all 31491

Trending Articles