Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def borderRound(self, val, up = True):
- try:
- val = float(val)
- except:
- return None
- if val==0: return val
- if val>=0:
- sign = 1
- else:
- up = not up
- sign = -1
- val = -val
- if up:
- log = math.ceil(math.log(val, 10))
- else:
- log = math.floor(math.log(val, 10))
- if log>=0:
- lim = 10**max(1,log-2)+0.0
- if lim / 2 > val:
- lim /= 2
- if up:
- val = math.ceil( val / lim ) * lim
- else:
- val = math.floor( val / lim ) * lim
- return sign * val
- else:
- return sign * (up and 1 or 0) #sign * math.ceil( val / 10 ) * 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement