Commit 1775bc9f by lijingjing

修约问题修改;

parent 5cffced4
......@@ -8,7 +8,7 @@ import java.math.RoundingMode;
public class Test {
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.2056", 2));
}
......@@ -27,21 +27,22 @@ public class Test {
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1)))
int beginIndex = value.lastIndexOf(".") + 1, valueLength = value.length();
String intVal = value.substring(0, value.indexOf(".") + 1);
int remindLength = valueLength - beginIndex;
String truncValue = "", zeroStr = "000000000";
// bdA = TRUNC(A1,B1+5)*10^B1
if (remindLength >= roundNum + 5) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum + 5);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum + 5);
} 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);
// bdB = TRUNC(A1,B1+5)*10^B1
if (remindLength >= roundNum) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum);
} 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();
......@@ -54,9 +55,9 @@ public class Test {
// 处理第三种情况
// CEILING(ABS(TRUNC(A1,B1+1)-0.5*10^(-B1),2*10^(-B1)*SIGN(A1))
if (remindLength >= roundNum + 1) {
truncValue = "0." + value.substring(beginIndex, beginIndex + roundNum + 1);
truncValue = intVal + value.substring(beginIndex, beginIndex + roundNum + 1);
} 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment