Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b_round_float.py
- n = [round(123456.789, -(i-3)) for i in xrange(10)]
- for i in n: print i
- '''
- output:
- 123456.789
- 123456.79
- 123456.8
- 123457.0
- 123460.0
- 123500.0
- 123000.0
- 120000.0
- 100000.0
- 0.0
- '''
- print
- def f(z): return str(abs(i))
- x = '-123456789'
- t = [float(x[i:]) for i in xrange(len(x))] ### as floats just for testing
- n = [float(('-' if i<0 else '')+f(i)[0]+'0'*(len(f(i))-3)) for i in t]
- for i in n: print i
- '''
- output:
- -100000000.0
- 100000000.0
- 20000000.0
- 3000000.0
- 400000.0
- 50000.0
- 6000.0
- 700.0
- 80.0
- 9.0
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement