Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xzxt-qyxzpt-report
Overview
Overview
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
刘良浪
xzxt-qyxzpt-report
Commits
d6f7f695
Commit
d6f7f695
authored
Dec 27, 2022
by
wuchengwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同比环比工具类
parent
4c4396f8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
src/main/java/org/springblade/founder/utils/NumberUtil.java
+35
-2
No files found.
src/main/java/org/springblade/founder/utils/NumberUtil.java
View file @
d6f7f695
...
...
@@ -12,8 +12,8 @@ public class NumberUtil {
/**
* 获取a所占b的百分比
* @param a
* @param b
* @param a
分子
* @param b
分母
* @return
*/
public
static
String
getPercent
(
int
a
,
int
b
){
...
...
@@ -27,4 +27,37 @@ public class NumberUtil {
nt
.
setMinimumFractionDigits
(
2
);
return
nt
.
format
(
percent
);
}
/**
* 同比环比增长或下降
* @param a 分子
* @param b 分母
* @return
*/
public
static
String
getTbhb
(
int
a
,
int
b
){
if
(
b
==
0
){
return
"0.00%"
;
}
double
percent
=
(
double
)
a
/
(
double
)
b
;
//正负控制 true + false -
boolean
falg
=
true
;
if
(
percent
<
1
){
percent
=
1
-
percent
;
falg
=
false
;
}
else
if
(
percent
>
1
)
{
percent
=
percent
-
1
;
}
//获取格式化对象
NumberFormat
nt
=
NumberFormat
.
getPercentInstance
();
//设置百分数精确度2即保留两位小数
nt
.
setMinimumFractionDigits
(
2
);
String
format
=
nt
.
format
(
percent
);
if
(
falg
){
return
"上升"
+
format
;
}
else
{
return
"下降"
+
format
;
}
}
}
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