from Custom import CustomBase import API import decimal class round2 (CustomBase): stack = None def __init__(self, stack): self.stack = stack # __init__ def help(self): msg = "round\n" msg += "-----\n\n" msg += "Rounds r1 to r0 digits after the coma\n\n" msg += "Takes r0 and r1 from the stack\n\n" msg += "Rounds r1 away from zero\n\n" msg += "Pushes the result to r0" API.showPopup('Custom function', msg, font=('Courier',API.helpFontSize)) # If you want to implement translated texts, you can use the API.t(textKey) function: # API.showPopup('Custom function', API.t(API.programName+'.CustomFunctions.square.btnHLP'), font=('Courier',API.helpFontSize)) # help def calculate(self): if self.stack.inputMode != 'DEC': API.toast('This operation is only supported in DEC mode') # If you want to implement translated texts, you can use the API.t(textKey) function: # API.toast(API.t(API.programName+'.CustomFunctions.square.onlySupportedinDEC')) return if self.stack.finishEntry() == -1: return # abort here because data in input line is invalid if self.stack.size() < 2: API.toast('This operation needs 2 arguments') return p = self.stack.getRegister(0) x = self.stack.getRegister(1) v = (10**p)*x v = v.to_integral_value(decimal.ROUND_HALF_UP)/(10**p) self.stack.pop(2) self.stack.push(v) # calculate # round2