root/trac/hacks/marketplugin/0.9/tracmarket/util.py

Revision 79 (checked in by stevegt, 6 years ago)

finish adding rudimentary Publish button

Line 
1
2 def XXXroundp(self, f):
3     '''round off price f to basket_price/100 precision'''
4     precision = math.log10(self.basket_price/100) * -1
5     return round(f, precision)
6        
7 # Price and Size need to be the same internal precision, because
8 # ledger transactions don't make a distinction between price or size
9 # types, but orders do; we'd have a reconcilation mess
10 class RoundedFloat(float):
11        
12     def __new__(cls, f):
13         '''convert to float and round off price f to 1/1000 precision'''
14         if f is None:
15             return None
16         val = round(float(f), 3)
17         self = float.__new__(cls, val)
18         return self
19
20 class Price(RoundedFloat):
21
22     def __str__(self):
23         return "%.2f" % self
24
25 class Size(RoundedFloat):
26        
27     def __str__(self):
28         return "%.1f" % self
29
Note: See TracBrowser for help on using the browser.