![]() |
#1 |
Junior Member
![]() Posts: 1
Karma: 10
Join Date: Oct 2021
Device: KOBO Aura H20
|
How to divide a custom column value?
Hello everyone,
I'm new to this forum so I hope I'm in the good place for this question. I use the Countpage plugin which displays the number of words of a epub in a custom column called "mots". What I want to do is to display a fraction of this number in another custom column called "durée" (so I can have the reading time of the book, based on my reading speed) I read some documentation about the calibre templates and functions and I try a lot, but I can't manage to perform this simple operation. I get an error each time i try. Can anyone explain to me which syntax to use for this operation? Thanks you very much ![]() Vianney |
![]() |
![]() |
![]() |
#2 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,725
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I searched this sub-forum for 'calculate' and found:
How many hours for a book Calculate reading time. Moderator Notice And, I moved your thread here because you must have missed this sticky PLEASE READ BEFORE POSTING - Purpose of Development subforum BR |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,211
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Quote:
I believe this is what you are asking for: Code:
program:
reading_time = divide(raw_field('#mots'), 50);
h = format_number(subtract(reading_time, fractional_part(reading_time)), '{0:0>2.0f}');
m = format_number(multiply(fractional_part(reading_time), 60), '{0:0>2.0f}');
reading_time = strcat(h, 'h ', m, 'm')
P.S.: I formatted the result to be more human readable. Ex.: '12.8' becomes '12h 48m'. Edit: You acctually mentioned words, not pages. But it works just the same. Just use your speed in words/hour. Last edited by thiago.eec; 10-30-2021 at 12:53 PM. Reason: Clarification |
|
![]() |
![]() |
![]() |
#4 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: reading_time = (if $$#mots == 'none' then 0 else $$#myfloat fi) / 50; h = format_number(floor(reading_time), '{0:0>2.0f}'); m = format_number(fractional_part(reading_time) * 60, '{0:0>2.0f}'); reading_time = strcat(h, 'h ', m, 'm') Code:
reading_time = $$#mots / 50; |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Using RE to extract pattern from custom column into another custom column | activedirectory | Library Management | 1 | 12-15-2019 08:07 PM |
Adding custom column with any lookup-name gives me empty column as a result? | Ahu Lee | Library Management | 16 | 06-09-2019 12:14 PM |
Move selected data from series column to a new custom column | fvdham | Library Management | 3 | 06-02-2017 03:49 PM |
Custom column returns value based on value of another custom column? | calvin-c | Calibre | 3 | 09-14-2013 02:24 PM |
how to move value(s) of tag column to a custom made column | zoorakhan | Library Management | 0 | 12-08-2012 03:53 AM |