![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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? |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)); Code:
program: divide(booksize(),add(field("#pages"),1)); |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 937
Karma: 53902736
Join Date: Jun 2015
Device: multiple
|
Thank you! Is there a way to round off or truncate the results?
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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}") 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. |
![]() |
![]() |
![]() |
#5 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 937
Karma: 53902736
Join Date: Jun 2015
Device: multiple
|
Thank you, that works nicely!
|
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
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 |