|
|
#1 |
|
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
I'm trying to make a saving template in Calibre. I want to get an identifier from my books and format it to remove left zeros.
For example, if identifier in a book is 0000123, I want my book be saved as "123". Identifiers are always 8 digit numbers, filled with zeros (00000001, 0000002, etc). I'm trying to use this template: {identifiers:select(my_id):G}, but I get an error saying "my_id" is not a number, but a string. I was looking at templates languages, but I can't find any function to convert a string to an integer. Anybody can help me?
Last edited by Pepin33; 11-10-2012 at 06:36 AM. |
|
|
|
|
|
#2 | |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,264
Karma: 61916422
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Identifiers: usually consists of 2 parts (the colon is the separator) 1) whose: amazon: 2) the string Maybe you want: identifier_in_list(val, id, found_val, not_found_val) |
|
|
|
|
|
|
#3 | |
|
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
Quote:
Now, I want to save those books using the identifier, but I want to remove left zeros. And if you're thinking about using book_id instead of my_id, not, that doesn't work, because the books are translated to another library so now my_id is not the same as the book_id... |
|
|
|
|
|
|
#4 | |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,264
Karma: 61916422
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
![]() use Nested commands (program mode),: convert the numeric string portion to a (integer)Number, then convert that back to a string. That should lose the leading zeros. |
|
|
|
|
|
|
#5 | |
|
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
Quote:
I tried with: program: str(int(template('[[identifiers:select(my_id)]]'))) But this doesn't work, and I can't find any function in template language to convert a string to an integer.... |
|
|
|
|
|
|
#6 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Take a look at the format_number function.
|
|
|
|
|
|
#7 |
|
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
|
|
|
|
|
|
#8 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program:format_number(select(field('identifiers'), 'my_id'), '{0:d}')
|
|
|
|
|
|
|
#9 |
|
Zealot
![]() ![]() ![]() ![]() ![]() Posts: 109
Karma: 419
Join Date: Aug 2012
Location: Spain
Device: Kindle Touch
|
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with template | KALKITO | Library Management | 1 | 07-02-2012 03:54 PM |
| Template language question | BookJunkieLI | Library Management | 7 | 02-02-2012 07:55 PM |
| v8.4 template error | cybmole | Calibre | 5 | 06-04-2011 12:10 PM |
| Stupid question about calibre language template | Cammagno | Calibre | 1 | 01-08-2011 09:00 AM |
| page-template ? | setzer | Calibre | 13 | 07-28-2009 12:23 AM |