Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Verifying numeric data
Hi Oracle fanciers,
I would like to check numeric data types already in a Java client to be able to react on potential an overflow or underflow exception (communication in my scenario is asynchronous, so that reporting errors to the client is more or less complicated).
After searching for a while I found the following constraints for the Oracle type NUMBER: Oracle's NUMBER ranges from 1.0E-130 to 9.9E125.
Is there an Oracle (v9i) method that does such validations for me?
Best regards from Black Forrest, Germany, Mattin
P.S.: Meanwhile I wrote a method that validates those ranges, but I would prefer to call somthing that automatically adopts when changing to another Oracle release.
static final double ORACLE_MAX_VALUE =
Double.parseDouble("9.999999999999998E125");
static final double ORACLE_MIN_VALUE =
Double.parseDouble("-9.999999999999998E125");
static final double ORACLE_SMALLEST_POSITIVE_VALUE =
Double.parseDouble("1.0E-130");
static final double ORACLE_SMALLEST_NEGATIVE_VALUE =
Double.parseDouble("-1.0E-130");
void validate(final double d) {
if (d == 0D) {
return;
}
if ((ORACLE_SMALLEST_NEGATIVE_VALUE < d) && (d <
ORACLE_SMALLEST_POSITIVE_VALUE)) {
throw new IllegalArgumentException("Out of maximum precision in range
[" + ORACLE_SMALLEST_NEGATIVE_VALUE
+ ";" +
ORACLE_SMALLEST_POSITIVE_VALUE + "].");
}
if (d < ORACLE_MIN_VALUE) {
throw new IllegalArgumentException("Value too small (less than " +
ORACLE_MIN_VALUE + ").");
}
if (d > ORACLE_MAX_VALUE) {
throw new IllegalArgumentException("Value too big (greater than " +
ORACLE_MAX_VALUE + ").");
}
}
Received on Mon Dec 13 2004 - 03:41:39 CST
![]() |
![]() |