mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Store: better comparable price function from Roman Mukhin.
This commit is contained in:
parent
a2a2c10ca1
commit
62c8cd7d4d
@ -22,13 +22,16 @@ from calibre.utils.icu import sort_key
|
|||||||
from calibre.utils.search_query_parser import SearchQueryParser
|
from calibre.utils.search_query_parser import SearchQueryParser
|
||||||
|
|
||||||
def comparable_price(text):
|
def comparable_price(text):
|
||||||
text = re.sub(r'[^0-9.,]', '', text)
|
# this keep thousand and fraction separators
|
||||||
delimeter = (',', '.')
|
match = re.search(r'(?:\d|[,.](?=\d))(?:\d*(?:[,.\' ](?=\d))?)+', text)
|
||||||
if len(text) < 3 or text[-3] not in delimeter:
|
if match:
|
||||||
text += '00'
|
# replace all separators with '.'
|
||||||
text = re.sub(r'\D', '', text)
|
m = re.sub(r'[.,\' ]', '.', match.group())
|
||||||
text = text.rjust(6, '0')
|
# remove all separators accept fraction,
|
||||||
return text
|
# leave only 2 digits in fraction
|
||||||
|
m = re.sub(r'\.(?!\d*$)', r'', m)
|
||||||
|
text = '{0:0>8.0f}'.format(float(m) * 100.)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
class Matches(QAbstractItemModel):
|
class Matches(QAbstractItemModel):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user