计算器 暂时没解决小数问题

Posted ch2020

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计算器 暂时没解决小数问题相关的知识,希望对你有一定的参考价值。

 1 import re
 2 
 3 num_one = (98798465*5465+4654-5464*45616846+84654)
 4 print(eval(num_one))
 5 
 6 total = 0
 7 print(num_one)
 8 while True:
 9     try:
10         a = re.search(((-)(d+), num_one)
11         if a:
12             num_one = num_one.replace(a.group(1), ‘‘, 1)
13             num_one = num_one.replace(), ‘‘)
14             num_one = num_one + str(-2 * int(a.group(2))) + )
15             print(num_one)
16         first = re.search([*|/], num_one)
17         print(first.group())
18         try:
19             if first.group() == *:
20                 num1 = re.findall((d+)*(d+), num_one)
21                 total1 = int(num1[0][0]) * int(num1[0][1])
22                 # total1 = int(num1[0][0]) * int(num1[0][1])
23                 total += total1
24                 num_one = re.sub(d+*d+, str(total1), num_one, 1)
25                 print(num_one, 11111)
26             elif first.group() == /:
27                 num1 = re.findall((d+)/(d+), num_one)
28                 total1 = int(num1[0][0]) / int(num1[0][1])
29                 total += total1
30                 num_one = re.sub(d+/d+, str(total1), num_one, 1)
31                 print(num_one)
32         except Exception as f:
33             break
34     except Exception as d:
35         break
36 while True:
37     try:
38         first = re.search(d+([+|-]), num_one)
39         print(first.group(1))
40         try:
41             if first.group(1) == +:
42                 num1 = re.findall((d+)+(d+), num_one)
43                 total1 = int(num1[0][0]) + int(num1[0][1])
44                 # total1 = int(num1[0][0]) * int(num1[0][1])
45                 total += total1
46                 num_one = re.sub(d++d+, str(total1), num_one, 1)
47                 print(num_one, 222222)
48             elif first.group(1) == -:
49                 num1 = re.findall((d+)-(d+), num_one)
50                 total1 = int(num1[0][0]) - int(num1[0][1])
51                 total += total1
52                 if total1 < 0 and len(re.findall(d+, num_one)) > 2:
53                     num_one = re.sub(d+-d+, str(abs(total1)), num_one, 1)
54                     num_one = num_one.replace(), ‘‘)
55                     num_one = num_one + str(total1 * 2) + )
56                 elif total1 < 0 and len(re.findall(d+, num_one)) <= 2:
57                     num_one = str(total1)
58                     break
59                 else:
60                     num_one = re.sub(d+-d+, str(total1), num_one, 1)
61                     print(num_one, 33333)
62         except Exception as f:
63             break
64     except Exception as d:
65         break
66 num_one = re.sub([()], ‘‘, num_one)
67 print(num_one)
68 输出:
69 290683253989
70 290683253989

 

以上是关于计算器 暂时没解决小数问题的主要内容,如果未能解决你的问题,请参考以下文章

计算机进行小数运算时出错的原因和避免方法

kendo treeview checkbox初始化选中问题,没解决,暂时记录下

php取随机数概率算法

Java 数字格式

指针作业

java 取Excel带有小数点数据,不能取完整,只能取小数点的后面2位,怎么解决?