mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-03 19:17:02 -05: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
 | 
			
		||||
 | 
			
		||||
def comparable_price(text):
 | 
			
		||||
    text = re.sub(r'[^0-9.,]', '', text)
 | 
			
		||||
    delimeter = (',', '.')
 | 
			
		||||
    if len(text) < 3 or text[-3] not in delimeter:
 | 
			
		||||
        text += '00'
 | 
			
		||||
    text = re.sub(r'\D', '', text)
 | 
			
		||||
    text = text.rjust(6, '0')
 | 
			
		||||
    return text
 | 
			
		||||
    # this keep thousand and fraction separators
 | 
			
		||||
    match = re.search(r'(?:\d|[,.](?=\d))(?:\d*(?:[,.\' ](?=\d))?)+', text)
 | 
			
		||||
    if match:
 | 
			
		||||
        # replace all separators with '.'
 | 
			
		||||
        m = re.sub(r'[.,\' ]', '.', match.group())
 | 
			
		||||
        # remove all separators accept fraction, 
 | 
			
		||||
        # 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):
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user