You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2004/11/23 20:17:42 UTC
svn commit: r106329 - /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
Author: djd
Date: Tue Nov 23 11:17:39 2004
New Revision: 106329
Modified:
incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
Log:
Fix Derby-74, new format of BigDecimal.toString() in J2SE 5.0
causes incorrect count of number of whole digits.
Fix contributed by Jeremy Boynes
Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java?view=diff&rev=106329&p1=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java&r1=106328&p2=incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java&r2=106329
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java (original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLDecimal.java Tue Nov 23 11:17:39 2004
@@ -26,18 +26,6 @@
import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.types.DataTypeDescriptor;
-import org.apache.derby.iapi.types.DataValueDescriptor;
-import org.apache.derby.iapi.types.TypeId;
-import org.apache.derby.iapi.types.NumberDataValue;
-import org.apache.derby.iapi.types.DataValueDescriptor;
-import org.apache.derby.iapi.types.BooleanDataValue;
-import org.apache.derby.iapi.types.StringDataValue;
-import org.apache.derby.iapi.types.VariableSizeDataValue;
-
-import org.apache.derby.iapi.types.TypeId;
-
-import org.apache.derby.iapi.services.io.FormatIdUtil;
import org.apache.derby.iapi.services.io.StoredFormatIds;
import org.apache.derby.iapi.services.io.Storable;
@@ -45,8 +33,6 @@
import org.apache.derby.iapi.services.cache.ClassSize;
-import org.apache.derby.iapi.types.*;
-
import java.math.BigDecimal;
import java.math.BigInteger;
import java.lang.Math;
@@ -691,12 +677,8 @@
*
* @param desiredType The type to normalize the source column to
* @param source The value to normalize
- * @param cachedDest DataValueDescriptor, if non-null, to hold result
- * (Reuse if normalizing multiple rows)
*
- * @return The normalized SQLDecimal
- *
- * @exception StandardException Thrown for null into
+ * @throws StandardException Thrown for null into
* non-nullable column, and for
* truncation error
*/
@@ -802,8 +784,6 @@
NumberDataValue result)
throws StandardException
{
- double tempResult;
-
if (result == null)
{
result = new SQLDecimal();
@@ -1031,7 +1011,7 @@
}
/**
*
- * @param the big decimal
+ * @param decimalValue the big decimal
*
* @return the precision
*/
@@ -1065,19 +1045,19 @@
return 0;
}
- /*
- ** Get the absolute value so we dont
- ** get a leading '-' sign. Make sure
- ** we don't count the leading '0' as
- ** precision. Would be nice to use log10, but
- ** we might be bigger than a double.
- */
- String s = decimalValue.abs().toString();
- int scale = decimalValue.scale();
- return (scale == 0) ?
- s.length() :
- s.indexOf('.') - (s.startsWith("0.") ? 1 : 0);
+ /**
+ * if ONE > abs(value) then the number of whole digits is 0
+ */
+ decimalValue = decimalValue.abs();
+ if (ONE.compareTo(decimalValue) == 1)
+ {
+ return 0;
+ }
+
+ String s = decimalValue.toString();
+ return (decimalValue.scale() == 0) ? s.length() : s.indexOf('.');
}
+
/**
* Return the value field
*