Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-15-2020, 08:27 PM   #1
MarjaE
Guru
MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.
 
Posts: 937
Karma: 53902736
Join Date: Jun 2015
Device: multiple
Column with Ratio of 2 other Columns?

Hi,

I'd like to set up a column tracking the ratio of size to #pages. My ideal format would be #ratio = (size*100)/(#pages+1).

The +1 is to avoid division by zero bugs when #pages is unknown.

I've looked in the manual, but the only ratios mentioned are aspect ratios.

I've looked in this thread: https://www.mobileread.com/forums/sh...t=column+ratio

And wrote this into "Template," but just get TEMPLATE ERROR

program: divide(field("size"),("#pages"+1));

So, uh, how should users build columns as ratios?
MarjaE is offline   Reply With Quote
Old 02-15-2020, 09:21 PM   #2
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
The problem is that the addition has to be done in a similar way to the division. So, it should be:

Code:
program: divide(field("size"),add(field("#pages"),1));
But, that actually gives zero for everything as the "size" column is always zero. You need to use the booksize function:

Code:
program: divide(booksize(),add(field("#pages"),1));
"booksize()" is the size in bytes for one of the formats for the book. It looks like it is the size of the largest format.
davidfor is offline   Reply With Quote
Advert
Old 02-15-2020, 09:54 PM   #3
MarjaE
Guru
MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.
 
Posts: 937
Karma: 53902736
Join Date: Jun 2015
Device: multiple
Thank you! Is there a way to round off or truncate the results?
MarjaE is offline   Reply With Quote
Old 02-15-2020, 10:23 PM   #4
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
You need to use "format_number":

Code:
program: format_number(divide(booksize(),add(raw_field("#pages"),1)),"{0:,.0f}")
The template editor has some details about the format string.

And using "raw_field" is a bit safer. I had an error on books with more than 1000 pages as my pages columns is formatted with commas.
davidfor is offline   Reply With Quote
Old 02-21-2020, 06:00 PM   #5
MarjaE
Guru
MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.MarjaE ought to be getting tired of karma fortunes by now.
 
Posts: 937
Karma: 53902736
Join Date: Jun 2015
Device: multiple
Thank you, that works nicely!
MarjaE is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
column from other columns with hierarchy and names DBorG Library Management 1 10-01-2018 04:03 PM
Column Built from other Columns question abqkjh Library Management 2 09-15-2017 11:08 AM
Yes/No column built from other columns barlowrm Calibre 5 11-17-2016 02:34 PM
Custom Column Build from other Columns Tanjamuse Library Management 7 10-16-2014 01:28 AM
Sorting fanfiction by like/dislike ratio using custom columns? crackshot91 Library Management 6 11-26-2013 02:47 PM


All times are GMT -4. The time now is 02:31 PM.


MobileRead.com is a privately owned, operated and funded community.