Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 08-22-2022, 04:42 PM   #1
astarinlife
Member
astarinlife doesn't litterastarinlife doesn't litter
 
astarinlife's Avatar
 
Posts: 12
Karma: 132
Join Date: Aug 2011
Device: Kindle Voyage, Kindle Paperwhite
Help Formatting Custom Column

I built a custom column and got that to do what I intended but the resulting number is probably 15 to 20 digits long. I'm trying to shorten it to just one digit after the decimal (0.1). I have two sets of code that do what I want that I will post in case one works better with formatting. I've looked around to try figuring it out and it seems like {0:.1f} should do what I want, but I have no clue where it would go. Any help is greatly appriciated!
Code:
{#kudos:'divide(multiply($, 100), field('#hits'))'}

program:
	kudos = field('#kudos');
	hits = field('#hits');
	percent = multiply(kudos, 100);
	divide(percent, hits);
astarinlife is offline   Reply With Quote
Old 08-22-2022, 09:16 PM   #2
allanahk
Connoisseur
allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.
 
allanahk's Avatar
 
Posts: 71
Karma: 2202292
Join Date: Nov 2018
Device: Kobo Libra 2
Try this:

Code:
program:
	kudos = field('#kudos');
	hits = field('#hits');
	percent = multiply(kudos, 100);
	format_number(divide(percent, hits), '{0:.1f}')
It's always fun playing around with custom columns The calibre template language is a big help
allanahk is offline   Reply With Quote
Advert
Old 08-22-2022, 11:14 PM   #3
astarinlife
Member
astarinlife doesn't litterastarinlife doesn't litter
 
astarinlife's Avatar
 
Posts: 12
Karma: 132
Join Date: Aug 2011
Device: Kindle Voyage, Kindle Paperwhite
Unfortunately that just shows the solution followed by the entire code written out. This is where I was getting stuck. I've been reading through that page and I've been trying things but I'm still suck between finding the right thing to do what I want and how to properly use it to make it work. Thank you for the suggestion though!
astarinlife is offline   Reply With Quote
Old 08-22-2022, 11:17 PM   #4
astarinlife
Member
astarinlife doesn't litterastarinlife doesn't litter
 
astarinlife's Avatar
 
Posts: 12
Karma: 132
Join Date: Aug 2011
Device: Kindle Voyage, Kindle Paperwhite
Never mind! It was missing a ; at the end. It works perfectly now!
astarinlife is offline   Reply With Quote
Old 08-22-2022, 11:24 PM   #5
allanahk
Connoisseur
allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.
 
allanahk's Avatar
 
Posts: 71
Karma: 2202292
Join Date: Nov 2018
Device: Kobo Libra 2
Quote:
Originally Posted by astarinlife View Post
Never mind! It was missing a ; at the end. It works perfectly now!
Whoops that was my mistake I'm glad you got it sorted!

For future reference, when you're editing a custom column and things aren't working I find it helpful to open the Template Editor or whatever it's called (which for some reason isn't really advertised anywhere on the help page...)

To access it, just highlight a book row in your library and click on the custom column entry (as if you were going to edit the entry if it was a simple column like title, author etc) and the editor should pop up and look like the attached pic. It updates in real time so you can play around with the coding to get it to work
Attached Thumbnails
Click image for larger version

Name:	temp.png
Views:	75
Size:	39.9 KB
ID:	196035  
allanahk is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Price Custom Column Formatting Help PaulineDesigns Library Management 13 07-22-2022 09:23 PM
Help formatting default value of custom column MerlinMama Library Management 2 08-28-2020 11:45 AM
Using RE to extract pattern from custom column into another custom column activedirectory Library Management 1 12-15-2019 08:07 PM
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
Formatting Floating Point # Custom Column GeekyGal Library Management 3 06-03-2011 05:34 PM


All times are GMT -4. The time now is 04:59 PM.


MobileRead.com is a privately owned, operated and funded community.