不影响的微调
This commit is contained in:
parent
7fd7366e32
commit
8a75c11182
5
kinit-api/.gitignore
vendored
5
kinit-api/.gitignore
vendored
@ -10,11 +10,6 @@ logs/*
|
|||||||
!logs/.gitkeep
|
!logs/.gitkeep
|
||||||
temp/*
|
temp/*
|
||||||
!temp/.gitkeep
|
!temp/.gitkeep
|
||||||
static/*
|
|
||||||
!static/redoc_ui
|
|
||||||
!static/swagger_ui
|
|
||||||
!static/system/favicon.ico
|
|
||||||
!static/system/logo.png
|
|
||||||
!alembic/versions/.gitkeep
|
!alembic/versions/.gitkeep
|
||||||
|
|
||||||
# dotenv
|
# dotenv
|
||||||
|
74
kinit-api/utils/compute.py
Normal file
74
kinit-api/utils/compute.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @version : 1.0
|
||||||
|
# @Creaet Time : 2022/5/12 17:09
|
||||||
|
# @File : compute.py
|
||||||
|
# @IDE : PyCharm
|
||||||
|
# @desc : 精准计算
|
||||||
|
from decimal import Decimal
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
|
class Compute:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def add(precision: int, *args: Union[float, Decimal]) -> float:
|
||||||
|
"""
|
||||||
|
相加
|
||||||
|
:param precision: 精度
|
||||||
|
"""
|
||||||
|
result = 0
|
||||||
|
for i in args:
|
||||||
|
if i is None:
|
||||||
|
i = 0
|
||||||
|
result += Decimal(str(i))
|
||||||
|
if precision == -1:
|
||||||
|
return float(result)
|
||||||
|
return round(float(result), precision)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def subtract(precision: int, *args: Union[float, Decimal]) -> float:
|
||||||
|
"""
|
||||||
|
相减
|
||||||
|
:param precision: 精度
|
||||||
|
"""
|
||||||
|
if args[0] is None:
|
||||||
|
start = 0
|
||||||
|
else:
|
||||||
|
start = args[0]
|
||||||
|
result = Decimal(str(start))
|
||||||
|
for i in args[1:]:
|
||||||
|
if i is None:
|
||||||
|
i = 0
|
||||||
|
result -= Decimal(str(i))
|
||||||
|
if precision == -1:
|
||||||
|
return float(result)
|
||||||
|
return round(float(result), precision)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def divide(precision: int, *args: Union[float, Decimal]) -> float:
|
||||||
|
"""
|
||||||
|
除法
|
||||||
|
:param precision: 精度
|
||||||
|
"""
|
||||||
|
result = Decimal(str(args[0]))
|
||||||
|
for i in args[1:]:
|
||||||
|
result = result / Decimal(str(i))
|
||||||
|
if precision == -1:
|
||||||
|
return float(result)
|
||||||
|
return round(float(result), precision)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def multiply(precision: int, *args: Union[float, Decimal]) -> float:
|
||||||
|
"""
|
||||||
|
乘法
|
||||||
|
:param precision: 精度
|
||||||
|
"""
|
||||||
|
result = Decimal(str(1))
|
||||||
|
for i in args:
|
||||||
|
if i is None:
|
||||||
|
i = 1
|
||||||
|
result = result * Decimal(str(i))
|
||||||
|
if precision == -1:
|
||||||
|
return float(result)
|
||||||
|
return round(float(result), precision)
|
Loading…
x
Reference in New Issue
Block a user