Tuesday, 6 August 2013

how to plus one at tail to a float number in python?

how to plus one at tail to a float number in python?

is there a simple and direct way to add 'one' at float number in python? i
means this:
if a == 0.0143:
a = plus(a)
assert a == 0.0144
sorry for i can't tell this well,since English not my mother tongue
a silly way i could think
def plus(a):
sa = str(a)
index = sa.find('.')
if index<0:
return a+1
else:
sb = '0'*len(sa)
sb[index] = '.'
sb[-1] = 1
return a+float(sb)
this may not be what i want,because it may give me a 0.0144000000001

No comments:

Post a Comment