import math
maxValue = 123 # maximum value
a = maxValue/4.0 # Python 2.x requires either numerator/denominator to be a float to return one
integerPart = str(a).split('.')[0] # if "a" is a decimal this selects the integer part
numberDigits = len(integerPart) # length of integerPart
def upperRound(x,N):
return ((x+N/2) // N) * N
print "Maximum value = {}".format(maxValue)
print "Maximum value/4 = {}".format(a)
print "length of integer part = {}".format(numberDigits)
print upperRound(a, 10-numberDigits)
Output:
Maximum value = 123
Maximum value/4 = 30.75
length of integer part = 2
32.0
Maybe this is more of a mathematical question than Python. How can I amend the 2nd argument in upperRound such that the value returned from it for maxValue=1234 is bigger than Maximum value/4=308.5, as is the result if applied in this situation?
Basically I want this script to be fully automated other than the maxValue being input by human, so for any maxValue/4, the output from upperRound should be bigger.