Skip to content

Commit

Permalink
Big decimal precision (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc authored Jan 25, 2023
1 parent 1192961 commit 19fe301
Show file tree
Hide file tree
Showing 2 changed files with 344 additions and 224 deletions.
22 changes: 19 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,25 @@ private void setTypeDefinition(DTV dtv) {
if (userProvidesPrecision) {
param.typeDefinition = SSType.DECIMAL.toString() + "(" + valueLength + "," + scale + ")";
}
} else
param.typeDefinition = SSType.DECIMAL.toString() + "(" + SQLServerConnection.maxDecimalPrecision
+ "," + scale + ")";
} else {
BigDecimal bigDecimal = null;
if (dtv.getJavaType() == JavaType.BIGDECIMAL
&& null != (bigDecimal = (BigDecimal) dtv.getSetterValue())) {

String[] plainValueArray = bigDecimal.abs().toPlainString().split("\\.");
param.typeDefinition = SSType.DECIMAL.toString() + "(" +
// Precision
(plainValueArray.length == 2 ? plainValueArray[0].length()
+ plainValueArray[1].length() : plainValueArray[0].length())
+ "," +
// Scale
(plainValueArray.length == 2 ? plainValueArray[1].length() : 0) + ")";

} else {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.maxDecimalPrecision + "," + scale + ")";
}
}

break;

Expand Down
Loading

0 comments on commit 19fe301

Please sign in to comment.