View Single Post
Old 06-17-2023, 07:32 PM   #639
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
When I tested your 21-pair template with #chaptercount, it produced the correct results.
Quote:
Originally Posted by estherflails View Post
For some reason it doesn't work for me :/ I even updated Calibre to the newest version but it didn't help. Any idea what the problem could be?
The problem is you are using text relational operators ('>=') to compare numeric values. With a text compare, 100 is less than 4 because it does a lexical comparison. You must use numeric relationals, as in '>=#'. See "Relational operators" section in The calibre template language.

Here is your template, corrected.
Code:
count = raw_field('#chapters');

chapters_count = switch_if(
    count >=# 100, 100, count >=# 95, 95, count >=# 90, 90, 
    count >=# 85, 85, count >=# 80, 80, count >=# 75, 75, 
    count >=# 70, 70, count >=# 65, 65, count >=# 60, 60, 
    count >=# 55, 55, count >=# 50, 50, count >=# 45, 45, 
    count >=# 40, 40, count >=# 35, 35, count >=# 30, 30, 
    count >=# 25, 25, count >=# 20, 20, count >=# 15, 15, 
    count >=# 10, 10, count >=# 5, 5, count >=# 1, 1, 0);
chaley is offline   Reply With Quote