View Single Post
Old 05-11-2022, 04:30 PM   #466
CyberPaul
Groupie
CyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheeseCyberPaul can extract oil from cheese
 
CyberPaul's Avatar
 
Posts: 159
Karma: 1000
Join Date: Aug 2016
Device: Kindle Voyage - Tolino Vision 4 HD - Kobo Sage
Quote:
Originally Posted by Svens View Post
On the next 4 screenshots,i'm using the following templates:
program:if ($$#words > 6000) then round(($$#words / 12000) - 1) else 0 fi
program: if ($$#words > 6000) then round($$#words / 12000) else 1 fi
Here, the results are very contradictory - some are OK, others are totally wrong. And I can't understand why.
I think I understood why. It looks like in the boolean condition #words is evaluated as a text string and the comparison is performed considering the alphabetic order! With this wrong interpretation you get for example "7">"6000"!
This is weird considering that #words is an integer!

try this instead:
Code:
program:if round($$#words / 12000) > 1 then round($$#words / 12000) - 1 else 0 fi
program:if round($$#words / 12000) > 1 then round($$#words / 12000) else 1 fi
Even though it is a little redundant (you divide and round twice in case the condition is returning true), this is forcing Calibre to manage it as an integer and... It works!
Does anybody know whether it is possible to force Calibre to consider it as an integer without performing an arithmetic operation? This would save computing time.

Last edited by CyberPaul; 05-11-2022 at 04:47 PM.
CyberPaul is offline   Reply With Quote