Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fulixin
dsk-operate-sys-cscec
Commits
370ab00e
Commit
370ab00e
authored
Mar 14, 2024
by
tianhongyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decimal封装优化,工料汇总80%
parent
0f5de350
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
29 deletions
+82
-29
decimal.js
dsk-operate-ui/src/utils/decimal.js
+11
-7
index.vue
...projectCostLedger/detail/components/FeedSummary/index.vue
+71
-22
No files found.
dsk-operate-ui/src/utils/decimal.js
View file @
370ab00e
...
...
@@ -11,7 +11,8 @@ export const add = (num1, num2, digit = 9, omit = false) => {
if
(
flag
)
throw
new
Error
(
"传入参数错误,参数不为number"
);
const
decimal1
=
new
Decimal
(
num1
);
const
decimal2
=
new
Decimal
(
num2
);
return
decimal1
.
plus
(
decimal2
).
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
const
result
=
decimal1
.
plus
(
decimal2
);
return
omit
?
result
.
toFixed
(
digit
,
Decimal
.
ROUND_UP
)
:
result
.
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
};
/**
...
...
@@ -20,12 +21,13 @@ export const add = (num1, num2, digit = 9, omit = false) => {
* @param {*} num2
* @returns
*/
export
const
subtract
=
(
num1
,
num2
,
digit
=
9
)
=>
{
export
const
subtract
=
(
num1
,
num2
,
digit
=
9
,
omit
=
false
)
=>
{
const
flag
=
(
!
parseFloat
(
num1
)
&&
parseFloat
(
num1
)
!=
"0"
)
||
(
!
parseFloat
(
num2
)
&&
parseFloat
(
num2
)
!=
"0"
);
if
(
flag
)
throw
new
Error
(
"传入参数错误,参数不为number"
);
const
decimal1
=
new
Decimal
(
num1
);
const
decimal2
=
new
Decimal
(
num2
);
return
decimal1
.
minus
(
decimal2
).
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
const
result
=
decimal1
.
minus
(
decimal2
);
return
omit
?
result
.
toFixed
(
digit
,
Decimal
.
ROUND_UP
)
:
result
.
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
};
/**
...
...
@@ -34,12 +36,13 @@ export const subtract = (num1, num2, digit = 9) => {
* @param {*} num2
* @returns
*/
export
const
multiply
=
(
num1
,
num2
,
digit
=
9
)
=>
{
export
const
multiply
=
(
num1
,
num2
,
digit
=
9
,
omit
=
false
)
=>
{
const
flag
=
(
!
parseFloat
(
num1
)
&&
parseFloat
(
num1
)
!=
"0"
)
||
(
!
parseFloat
(
num2
)
&&
parseFloat
(
num2
)
!=
"0"
);
if
(
flag
)
throw
new
Error
(
"传入参数错误,参数不为number"
);
const
decimal1
=
new
Decimal
(
num1
);
const
decimal2
=
new
Decimal
(
num2
);
return
decimal1
.
times
(
decimal2
).
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
const
result
=
decimal1
.
times
(
decimal2
);
return
omit
?
result
.
toFixed
(
digit
,
Decimal
.
ROUND_UP
)
:
result
.
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
};
/**
...
...
@@ -48,10 +51,11 @@ export const multiply = (num1, num2, digit = 9) => {
* @param {*} num2
* @returns
*/
export
const
divide
=
(
num1
,
num2
,
digit
=
9
)
=>
{
export
const
divide
=
(
num1
,
num2
,
digit
=
9
,
omit
=
false
)
=>
{
const
flag
=
(
!
parseFloat
(
num1
)
&&
parseFloat
(
num1
)
!=
"0"
)
||
(
!
parseFloat
(
num2
)
&&
parseFloat
(
num2
)
!=
"0"
);
if
(
flag
)
throw
new
Error
(
"传入参数错误,参数不为number"
);
const
decimal1
=
new
Decimal
(
num1
);
const
decimal2
=
new
Decimal
(
num2
);
return
decimal1
.
dividedBy
(
decimal2
).
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
const
result
=
decimal1
.
dividedBy
(
decimal2
);
return
omit
?
result
.
toFixed
(
digit
,
Decimal
.
ROUND_UP
)
:
result
.
toDecimalPlaces
(
digit
,
Decimal
.
ROUND_UP
).
toString
();
};
dsk-operate-ui/src/views/projectCostLedger/detail/components/FeedSummary/index.vue
View file @
370ab00e
This diff is collapsed.
Click to expand it.
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