Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
cca1b7ea
Commit
cca1b7ea
authored
Apr 22, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复bug
parent
35df541f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
CalcHelper.java
...src/main/java/com/yanzuoguang/util/helper/CalcHelper.java
+95
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CalcHelper.java
View file @
cca1b7ea
...
@@ -24,6 +24,21 @@ public class CalcHelper {
...
@@ -24,6 +24,21 @@ public class CalcHelper {
return
b1
.
add
(
b2
).
doubleValue
();
return
b1
.
add
(
b2
).
doubleValue
();
}
}
/**
* 相加
*
* @param d1
* @param d2
* @return
*/
public
static
double
addList
(
double
d1
,
double
...
d2
)
{
double
ret
=
d1
;
for
(
double
item
:
d2
)
{
ret
=
add
(
ret
,
item
);
}
return
ret
;
}
/**
/**
* 相减
* 相减
*
*
...
@@ -35,7 +50,21 @@ public class CalcHelper {
...
@@ -35,7 +50,21 @@ public class CalcHelper {
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
return
b1
.
subtract
(
b2
).
doubleValue
();
}
/**
* 相减
*
* @param d1
* @param d2
* @return
*/
public
static
double
subList
(
double
d1
,
double
...
d2
)
{
double
ret
=
d1
;
for
(
double
item
:
d2
)
{
ret
=
sub
(
ret
,
item
);
}
return
ret
;
}
}
/**
/**
...
@@ -49,7 +78,21 @@ public class CalcHelper {
...
@@ -49,7 +78,21 @@ public class CalcHelper {
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
return
b1
.
multiply
(
b2
).
doubleValue
();
return
b1
.
multiply
(
b2
).
doubleValue
();
}
/**
* 相乘
*
* @param d1
* @param d2
* @return
*/
public
static
double
mulList
(
double
d1
,
double
...
d2
)
{
double
ret
=
d1
;
for
(
double
item
:
d2
)
{
ret
=
mul
(
ret
,
item
);
}
return
ret
;
}
}
/**
/**
...
@@ -78,7 +121,59 @@ public class CalcHelper {
...
@@ -78,7 +121,59 @@ public class CalcHelper {
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
return
b1
.
divide
(
b2
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
b1
.
divide
(
b2
,
scale
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
}
/**
* 相除
*
* @param d1
* @param d2
* @return
*/
public
static
double
divList
(
double
d1
,
double
...
d2
)
{
double
ret
=
d1
;
for
(
double
item
:
d2
)
{
ret
=
div
(
ret
,
item
);
}
return
ret
;
}
/**
* 转换为金额
*
* @param from 来源数据
* @param scale 保留浮点数
* @param roundingMode 四舍五入类型
* @return 转换为金额
*/
public
static
double
toMoney
(
double
from
,
int
scale
,
int
roundingMode
)
{
return
new
BigDecimal
(
Double
.
toString
(
from
))
.
setScale
(
scale
,
roundingMode
)
.
doubleValue
()
;
}
}
/**
* 转换为金额
*
* @param from 来源数据
* @return 转换为金额
*/
public
static
double
toMoney
(
double
from
)
{
return
toMoney
(
from
,
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
/**
* 判断是否相等
*
* @param d1
* @param d2
* @return
*/
public
static
boolean
equals
(
double
d1
,
double
d2
)
{
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
d1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
d2
));
return
b1
.
equals
(
b2
);
}
}
}
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