提交 f48e3cac authored 作者: S.Vladykin's avatar S.Vladykin

merge from master

......@@ -27,6 +27,8 @@ Change Log
</li>
<li>Issue #186: The "script" command did not include sequences of temporary tables.
</li>
<li>Issue #115: to_char fails with pattern FM0D099
</li>
</ul>
<h2>Version 1.4.190 Beta (2015-10-11)</h2>
......
......@@ -11,6 +11,7 @@ import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Currency;
import java.util.GregorianCalendar;
......@@ -219,7 +220,7 @@ public class ToChar {
}
StringBuilder output = new StringBuilder();
String unscaled = number.unscaledValue().abs().toString();
String unscaled = (number.abs().compareTo(BigDecimal.ONE) < 0 ? zeroesAfterDecimalSeparator(number) : "") + number.unscaledValue().abs().toString();
// start at the decimal point and fill in the numbers to the left,
// working our way from right to left
......@@ -328,6 +329,26 @@ public class ToChar {
return output.toString();
}
private static String zeroesAfterDecimalSeparator(BigDecimal number) {
final String numberStr = number.toString();
final int idx = numberStr.indexOf('.');
if (idx >= 0 ) {
int i = idx + 1;
boolean allZeroes = true;
for (; i < numberStr.length(); i++) {
if (numberStr.charAt(i) != '0') {
allZeroes = false;
break;
}
}
final char[] zeroes = new char[allZeroes ? numberStr.length() - idx - 1: i - 1 - idx];
Arrays.fill(zeroes, '0');
return String.valueOf(zeroes);
} else {
return "";
}
}
private static void addSign(StringBuilder output, int signum,
boolean leadingSign, boolean trailingSign, boolean trailingMinus,
boolean angleBrackets, boolean fillMode) {
......
......@@ -1699,6 +1699,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertThrows(ErrorCode.INVALID_TO_CHAR_FORMAT, stat,
"SELECT TO_CHAR(123.45, 'q999.99') FROM DUAL");
// ISSUE-115
assertResult("0.123", stat, "select to_char(0.123, 'FM0.099') from dual;");
assertResult("1.123", stat, "select to_char(1.1234, 'FM0.099') from dual;");
assertResult("1.1234", stat, "select to_char(1.1234, 'FM0.0999') from dual;");
assertResult("1.023", stat, "select to_char(1.023, 'FM0.099') from dual;");
assertResult("0.012", stat, "select to_char(0.012, 'FM0.099') from dual;");
assertResult("0.123", stat, "select to_char(0.123, 'FM0.099') from dual;");
assertResult("0.001", stat, "select to_char(0.001, 'FM0.099') from dual;");
assertResult("0.001", stat, "select to_char(0.0012, 'FM0.099') from dual;");
assertResult("0.002", stat, "select to_char(0.0019, 'FM0.099') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D099') from dual;");
assertResult("0.00", stat, "select to_char(0., 'FM0D009') from dual;");
assertResult("0.", stat, "select to_char(0, 'FM0D9') from dual;");
assertResult("0.0", stat, "select to_char(0.0, 'FM0D099') from dual;");
assertResult("0.00", stat, "select to_char(0.00, 'FM0D009') from dual;");
assertResult("0.00", stat, "select to_char(0, 'FM0D009') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D09') from dual;");
assertResult("0.0", stat, "select to_char(0, 'FM0D0') from dual;");
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论