View Single Post
Old 06-16-2023, 03:09 PM   #6
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,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
You may also be able to use a composite column that checks the integer and convert it to text. But that's a bit more of an effort.
For fun I made a template for a composite column to calculate the ordinal from the integer. You put the integer of the edition in some column, in my case #myint. You make a composite column with one of these two templates. You would sort and search on the integer column. You would display the composite.

General Program Mode:
Code:
program:
	n = raw_field('#myint', '');
	if n then
		t = mod(n, 100);
		if t >=# 4 && t <=# 20 then
			suffix = 'th'
		else
			dex = mod(t, 10);
			if dex >=# 4 then dex = 4 fi;
			suffix = list_item('th,st,nd,rd,th', dex, ',')
		fi;
		return n & suffix
	fi;
	return ''
Python Template Mode (much faster):
Code:
python:
def evaluate(book, context):
	n = book.get('#myint')	
	if n is None:
		return ''
	if 4 <= (n % 100) <= 20:
		suffix = 'th'
	else:
		suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]
	return str(n) + suffix
(Code from Stack Overflow)

Quote:
Originally Posted by theducks View Post
Personally, I just append (2nd ed) to the title
Stuff in the paren does not affect the sort value
But it does affect searching.
chaley is offline   Reply With Quote