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
57478123
authored
Jan 20, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化中文参数带小数点,除号等
parent
991c96e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
utils/functions.py
utils/functions.py
View file @
57478123
...
@@ -84,11 +84,18 @@ def word_conversion(unit_res, kw):
...
@@ -84,11 +84,18 @@ def word_conversion(unit_res, kw):
if
unit_str
in
cast_map
:
if
unit_str
in
cast_map
:
for
unit_key
,
unit_data
in
unit_map
.
items
():
for
unit_key
,
unit_data
in
unit_map
.
items
():
if
cast_map
[
unit_str
]
in
unit_data
:
if
cast_map
[
unit_str
]
in
unit_data
:
if
unit_data
[
cast_map
[
unit_str
]]
==
1
:
if
"/"
not
in
kw
:
# 单独处理除号
true_unit
=
unit_key
if
"."
in
kw
:
# 包含小数点
unit_num
=
float
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
cast_map
[
unit_str
]]))
+
unit_key
else
:
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
cast_map
[
unit_str
]]))
+
unit_key
else
:
else
:
true_unit
=
str
(
unit_data
[
cast_map
[
unit_str
]])
+
unit_key
num_list
=
kw
.
replace
(
unit_str
,
""
)
.
split
(
"/"
)
return
kw
.
replace
(
unit_str
,
true_unit
)
unit_num
=
round_up
(
int
(
num_list
[
0
])
/
int
(
num_list
[
1
]))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
cast_map
[
unit_str
]]))
+
unit_key
return
true_unit
return
None
return
None
...
@@ -121,6 +128,7 @@ def unit_conversion(unit_res, kw):
...
@@ -121,6 +128,7 @@ def unit_conversion(unit_res, kw):
return
None
return
None
def
delete_extra_zero
(
n
):
def
delete_extra_zero
(
n
):
'''删除小数点后多余的0'''
'''删除小数点后多余的0'''
if
isinstance
(
n
,
int
):
if
isinstance
(
n
,
int
):
...
@@ -130,6 +138,7 @@ def delete_extra_zero(n):
...
@@ -130,6 +138,7 @@ def delete_extra_zero(n):
n
=
int
(
n
.
rstrip
(
'.'
))
if
n
.
endswith
(
'.'
)
else
float
(
n
)
# 只剩小数点直接转int,否则转回float
n
=
int
(
n
.
rstrip
(
'.'
))
if
n
.
endswith
(
'.'
)
else
float
(
n
)
# 只剩小数点直接转int,否则转回float
return
n
return
n
def
round_up
(
value
):
def
round_up
(
value
):
return
round
(
value
*
1000
)
/
1000.0
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