forked from Jayhello/python_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnum_ope.py
More file actions
44 lines (31 loc) · 662 Bytes
/
Copy pathnum_ope.py
File metadata and controls
44 lines (31 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# _*_coding:utf-8 _*_
"""
float decimal points
https://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points
"""
def round_float():
f = 3.1415
print round(f, 2)
# 3.14
a = 13.95
print a
# 13.95
print "%.2f" % a
# 13.95
print "%.2f" % 13.9499999
# 13.95
a = 13.949999999999999
print format(a, '.2f')
# 13.95
def or_shift():
print 1 >> 1, 1 << 1 # 0 2
print 1 | 4, 1 | 2 # 5 3
def print_binary():
m, n = 5, -5
print '{0:b}'.format(m)
print '{0:b}'.format(n)
print bin(m), bin(n)
if __name__ == '__main__':
print_binary()
# round_float()
pass