Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
patzn-cloud-service-hmhj
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
wangweidong
patzn-cloud-service-hmhj
Commits
1775bc9f
Commit
1775bc9f
authored
Jan 05, 2022
by
lijingjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修约问题修改;
parent
5cffced4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
Test.java
src/test/java/com/patzn/cloud/service/lims/test/Test.java
+8
-7
No files found.
src/test/java/com/patzn/cloud/service/lims/test/Test.java
View file @
1775bc9f
...
@@ -8,7 +8,7 @@ import java.math.RoundingMode;
...
@@ -8,7 +8,7 @@ import java.math.RoundingMode;
public
class
Test
{
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
getTestValue
(
"
0.1841
"
,
2
));
System
.
out
.
println
(
getTestValue
(
"
65.475
"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.1952"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.1952"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.2056"
,
2
));
System
.
out
.
println
(
getTestValue
(
"0.2056"
,
2
));
}
}
...
@@ -27,21 +27,22 @@ public class Test {
...
@@ -27,21 +27,22 @@ public class Test {
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int
beginIndex
=
value
.
lastIndexOf
(
"."
)
+
1
,
valueLength
=
value
.
length
();
int
beginIndex
=
value
.
lastIndexOf
(
"."
)
+
1
,
valueLength
=
value
.
length
();
String
intVal
=
value
.
substring
(
0
,
value
.
indexOf
(
"."
)
+
1
);
int
remindLength
=
valueLength
-
beginIndex
;
int
remindLength
=
valueLength
-
beginIndex
;
String
truncValue
=
""
,
zeroStr
=
"000000000"
;
String
truncValue
=
""
,
zeroStr
=
"000000000"
;
// bdA = TRUNC(A1,B1+5)*10^B1
// bdA = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
+
5
)
{
if
(
remindLength
>=
roundNum
+
5
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
5
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
5
);
}
else
{
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
5
-
remindLength
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
5
-
remindLength
);
}
}
BigDecimal
bdDiff
=
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
);
BigDecimal
bdDiff
=
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
);
// bdB = TRUNC(A1,B1+5)*10^B1
// bdB = TRUNC(A1,B1+5)*10^B1
if
(
remindLength
>=
roundNum
)
{
if
(
remindLength
>=
roundNum
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
);
}
else
{
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
-
remindLength
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
-
remindLength
);
}
}
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
)).
abs
();
bdDiff
=
bdDiff
.
subtract
(
new
BigDecimal
(
truncValue
).
scaleByPowerOfTen
(
roundNum
)).
abs
();
...
@@ -54,9 +55,9 @@ public class Test {
...
@@ -54,9 +55,9 @@ public class Test {
// 处理第三种情况
// 处理第三种情况
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
if
(
remindLength
>=
roundNum
+
1
)
{
if
(
remindLength
>=
roundNum
+
1
)
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
1
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
,
beginIndex
+
roundNum
+
1
);
}
else
{
}
else
{
truncValue
=
"0."
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
1
-
remindLength
);
truncValue
=
intVal
+
value
.
substring
(
beginIndex
)
+
zeroStr
.
substring
(
0
,
roundNum
+
1
-
remindLength
);
}
}
bdDiff
=
new
BigDecimal
(
truncValue
);
bdDiff
=
new
BigDecimal
(
truncValue
);
...
...
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