-
Notifications
You must be signed in to change notification settings - Fork 0
/
nm.py
39 lines (35 loc) · 933 Bytes
/
nm.py
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
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
def tran(value):
if value[-1] == 'f':
value = float(value[:-1]+'e-15')
elif value[-1] == 'p':
value = float(value[:-1]+'e-12')
elif value[-1] == 'n':
value = float(value[:-1]+'e-9')
elif value[-1] == 'u':
value = float(value[:-1]+'e-6')
elif value[-1] == 'm':
value = float(value[:-1]+'e-3')
elif value[-1] == 'k':
value = float(value[:-1]+'e3')
elif value[-1] == 'meg':
value = float(value[:-1]+'e6')
elif value[-1] == 'g':
value = float(value[:-1]+'e9')
elif value[-1] == 't':
value = float(value[:-1]+'e12')
else :
value = float(value)
return value