Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
991c96e7
authored
Jan 20, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
去掉小数点后多余的0
parent
a546d8bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
utils/functions.py
utils/functions.py
View file @
991c96e7
...
...
@@ -106,21 +106,29 @@ def unit_conversion(unit_res, kw):
if
"/"
not
in
kw
:
# 单独处理除号
if
"
%
"
in
kw
:
# 百分号的单独处理
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
unit_num
*
unit_data
[
unit_str
]
)
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
])
)
elif
"."
in
kw
:
unit_num
=
float
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
unit_num
*
unit_data
[
unit_str
]
)
+
unit_key
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
])
)
+
unit_key
else
:
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
unit_num
*
unit_data
[
unit_str
]
)
+
unit_key
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
])
)
+
unit_key
else
:
num_list
=
kw
.
replace
(
unit_str
,
""
)
.
split
(
"/"
)
unit_num
=
round_up
(
int
(
num_list
[
0
])
/
int
(
num_list
[
1
]))
true_unit
=
str
(
unit_num
*
unit_data
[
unit_str
]
)
+
unit_key
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
])
)
+
unit_key
return
true_unit
return
None
def
delete_extra_zero
(
n
):
'''删除小数点后多余的0'''
if
isinstance
(
n
,
int
):
return
n
if
isinstance
(
n
,
float
):
n
=
str
(
n
)
.
rstrip
(
'0'
)
# 删除小数点后多余的0
n
=
int
(
n
.
rstrip
(
'.'
))
if
n
.
endswith
(
'.'
)
else
float
(
n
)
# 只剩小数点直接转int,否则转回float
return
n
def
round_up
(
value
):
return
round
(
value
*
1000
)
/
1000.0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment