Class java.sql.Numeric
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.sql.Numeric

java.lang.Object
   |
   +----java.lang.Number
           |
           +----java.sql.Numeric

public final class Numeric
extends Number

The java.sql.Numeric class is an arbitrary precision and scale number class that can be used to represent SQL fixed point NUMERIC and DECIMAL values.

Numeric objects are composed of four properties:

The theoretical limit to the precision and scale values is 0x7fffffff. Numeric objects are immutable.

Constructor Index

 o Numeric(double, int)
Construct a Numeric from a double given a double value and an integer scale.
 o Numeric(int, int)
Construct a Numeric from an integer given an integer value and an integer scale.
 o Numeric(Numeric)
Construct a Numeric from another Numeric.
 o Numeric(Numeric, int)
Given an existing Numeric and an integer scale value, construct a new Numeric with the scale adjusted accordingly.
 o Numeric(String)
Creates a numeric from a string.
 o Numeric(String, int)
Construct a Numeric given a String and an integer scale.

Method Index

 o add(Numeric)
Returns the arithmetic sum of the Numeric and the argument.
 o createFromScaled(long, int)
Return a numeric value created by dividing the argument by 10**scale.
 o debug()
 o divide(Numeric)
Returns the arithmentic quotient calculated by dividing the Numeric by the argument.
 o doubleValue()
Convert the Numeric value to the Java built-in type of double.
 o equals(Object)
Returns true if the arithmetic value of the Numeric equals the argument.
 o floatValue()
Convert the Numeric value to the Java built-in type of float.
 o getRoundingValue()
Returns the value of the roundingValue which is used in rounding operations.
 o getScale()
Return the number of digits to the right of the decimal point.
 o getScaled()
Return the value multiplied by 10**scale.
 o greaterThan(Numeric)
Returns true if the arithmetic value of the Numeric is greater than the argument.
 o greaterThanOrEquals(Numeric)
Returns true if the arithmetic value of the Numeric is greater than or equals the argument.
 o hashCode()
Returns an integer hashcode for the Numeric.
 o intValue()
Convert the Numeric value to the Java built-in type of int.
 o lessThan(Numeric)
Returns true if the arithmetic value of the Numeric is less than the argument.
 o lessThanOrEquals(Numeric)
Returns true if the arithmetic value of the Numeric is less than or equals the argument.
 o longValue()
Convert the Numeric value to the Java built-in type of long.
 o multiply(Numeric)
Returns the arithmetic product of the object Numeric and the argument.
 o setRoundingValue(int)
Sets the value of the roundingValue which is used in rounding operations.
 o setScale(int)
Returns a numeric copied from the current object with the scale adjusted as specified by the argument.
 o subtract(Numeric)
Returns the arithmetic difference between the Numeric and the argument.
 o toString()
Convert the Numeric value to the Java built-in type of String.

Constructors

 o Numeric
  public Numeric(String s)
Creates a numeric from a string. The string may contain a sign and a decimal point, e.g "-55.12". Spaces and other non-numeric characters are ignored.
Parameters:
s - the string used to initialize the Numeric.
 o Numeric
  public Numeric(String s,
                 int scale)
Construct a Numeric given a String and an integer scale. The scale represents the desired number of places to the right of the decimal point.

The String may contain a sign and a decimal point, e.g. "-55.12". The scale must be an integer with value greater than or equal to zero. If the scale differs from the implicit decimal point given in the String the value is adjusted to the given scale. This may involve rounding.

For example, Numeric("99.995",2) would result in a numeric with a scale of 2 and a value of "100.00". If the String contains no decimal point, then the scale is determined solely by the given integer scale. No implicit decimal point is assumed. For example, the constructor Numeric("123",2) creates a Numeric with a scale of 2, a precision of 5, and a value of "123.00".

Note: Rounding is controlled by the roundingIndex function.

Parameters:
s - the string used to initialize the Numeric.
scale - the value greater than or equal to zero representing the desired number of digits to the right of the decimal point.
 o Numeric
  public Numeric(int x,
                 int scale)
Construct a Numeric from an integer given an integer value and an integer scale. The scale is set to the value specified. No implicit decimal point is assumed, i.e., if the double value is "1234" and the scale 2, the resulting numeric will be "1234.00.
Parameters:
x - The double value used to initialize the new Numeric.
scale - The desired number of digits after the decimal point.
 o Numeric
  public Numeric(double x,
                 int scale)
Construct a Numeric from a double given a double value and an integer scale. The scale is set to the value specified. No implicit decimal point is assumed, i.e., if the double value is "1234" and the scale 2, the resulting numeric will be "1234.00. If the double value is "1234.5" and the scale 2 the value will be "1234.50". Rounding may occur during this conversion.
Parameters:
x - The double value used to initialize the new Numeric.
scale - The desired number of digits after the decimal point.
 o Numeric
  public Numeric(Numeric x)
Construct a Numeric from another Numeric. The precision, scale, and value of the new Numeric are copied from the Numeric given in the argument.
Parameters:
x - The Numeric used to initialize the new Numeric.
 o Numeric
  public Numeric(Numeric x,
                 int scale)
Given an existing Numeric and an integer scale value, construct a new Numeric with the scale adjusted accordingly. The precision, scale, and value of the new Numeric are copied from the argument Numeric. The scale is then adjusted to the scale given as a parameter. This may result in rounding of the value, as well as a change to the precision.
Parameters:
x - The Numeric to copy.
scale - An integer representing the desired * scale of the new Numeric.

Methods

 o setRoundingValue
  public static void setRoundingValue(int val)
Sets the value of the roundingValue which is used in rounding operations. The roundingValue is a digit between 0 and 9 that determines rounding behavior. When the scale of a Numeric is reduced either by request or in a calculation, rounding is performed if the value of the scale + 1 digit to the right of the decimal point is greater than the rounding index.

For example, if the number is 1.995, and the scale is set to 2 and the roundingValue is 4, then the number would be rounded to 2.00. The default roundingValue is 4. A roundingValue of 9 cancels rounding.

Parameters:
val - The value between 0 and 9 of the desired roundingValue.
 o getRoundingValue
  public static int getRoundingValue()
Returns the value of the roundingValue which is used in rounding operations. The roundingValue is a digit between 0 and 9 that determines rounding behavior. When the scale of a Numeric is reduced either by request or in a calculation, rounding is performed if the value of the scale + 1 digit to the right of the decimal point is greater than the rounding index.

For example, if the number is 1.995, and the scale is set to 2 and the RoundingValue is 4, then the number would be rounded to 2.00. The default roundingValue is 4. A roundingValue of 9 cancels rounding.

Returns:
rounding value
 o intValue
  public int intValue()
Convert the Numeric value to the Java built-in type of int. This conversion may result in a loss of precision. Digits after the decimal point are dropped.
Returns:
An integer representation of the Numeric value.
Overrides:
intValue in class Number
 o longValue
  public long longValue()
Convert the Numeric value to the Java built-in type of long. This conversion may result in a loss of precision. Digits after the decimal point are dropped.
Returns:
A long integer representation of the Numeric value.
Overrides:
longValue in class Number
 o floatValue
  public float floatValue()
Convert the Numeric value to the Java built-in type of float. This conversion may result in a loss of precision.
Returns:
A float representation of the Numeric value.
Overrides:
floatValue in class Number
 o doubleValue
  public double doubleValue()
Convert the Numeric value to the Java built-in type of double. This conversion may result in a loss of precision.
Returns:
A double representation of the Numeric value.
Overrides:
doubleValue in class Number
 o toString
  public String toString()
Convert the Numeric value to the Java built-in type of String. Negative numbers are represented by a leading "-". No sign is added for positive numbers.
Returns:
A String representation of the Numeric value.
Overrides:
toString in class Object
 o getScale
  public int getScale()
Return the number of digits to the right of the decimal point.
Returns:
An integer value representing the number of decimal places to the right of the decimal point.
 o getScaled
  public long getScaled()
Return the value multiplied by 10**scale. Precision may be lost. Thus, if a currency value was being kept with scale "2" as "5.04", the getScaled function would return the long integer "504".
Returns:
The scaled value as a long.
 o createFromScaled
  public static Numeric createFromScaled(long scaled,
                                         int s)
Return a numeric value created by dividing the argument by 10**scale. Thus, createFromScaled(504,2) would create the value "5.04".
Parameters:
scaled - The scaled value as a long.
s - The desired scale value as an integer between 0 and 9
Returns:
A new numeric.
 o add
  public Numeric add(Numeric n)
Returns the arithmetic sum of the Numeric and the argument. The scale of the sum is determined by this object not by the argument.
Parameters:
n - The Numeric to add.
Returns:
The sum as a Numeric.
 o subtract
  public Numeric subtract(Numeric n)
Returns the arithmetic difference between the Numeric and the argument. The scale of the sum is determined by this object not by the argument.
Parameters:
n - The Numeric to subtract.
Returns:
The difference as a Numeric.
 o multiply
  public Numeric multiply(Numeric x)
Returns the arithmetic product of the object Numeric and the argument. The scale of the product is determined by this object not by the argument.
Parameters:
x - The multiplier as a Numeric.
Returns:
The product as a Numeric.
 o divide
  public Numeric divide(Numeric x)
Returns the arithmentic quotient calculated by dividing the Numeric by the argument. The scale of the quotient is determined by this object not by the argument.
Parameters:
x - The divisor as a Numeric.
Returns:
The quotient as a Numeric.
 o equals
  public boolean equals(Object obj)
Returns true if the arithmetic value of the Numeric equals the argument.
Parameters:
obj - The object to compare.
Returns:
The boolean result of the comparison.
Overrides:
equals in class Object
 o lessThan
  public boolean lessThan(Numeric x)
Returns true if the arithmetic value of the Numeric is less than the argument.
Parameters:
x - The object to compare.
Returns:
The boolean result of the comparison.
 o lessThanOrEquals
  public boolean lessThanOrEquals(Numeric x)
Returns true if the arithmetic value of the Numeric is less than or equals the argument.
Parameters:
x - The object to compare.
Returns:
The boolean result of the comparison.
 o greaterThan
  public boolean greaterThan(Numeric x)
Returns true if the arithmetic value of the Numeric is greater than the argument.
Parameters:
x - The object to compare.
Returns:
The boolean result of the comparison.
 o greaterThanOrEquals
  public boolean greaterThanOrEquals(Numeric x)
Returns true if the arithmetic value of the Numeric is greater than or equals the argument.
Parameters:
x - The object to compare.
Returns:
The boolean result of the comparison.
 o hashCode
  public int hashCode()
Returns an integer hashcode for the Numeric. Note that the code returned for 03.00 will equal the code for 3.0.
Returns:
The hashcode as an integer.
Overrides:
hashCode in class Object
 o setScale
  public Numeric setScale(int scale)
Returns a numeric copied from the current object with the scale adjusted as specified by the argument. Sets the number of the digits to the right of the decimal point. The precision and value of the Numeric will be adjusted accordingly. Note that changing the scale to a smaller value may result in rounding the value.
Parameters:
scale - the character to be converted
Returns:
A Numeric with the adjusted scale.
See Also:
roundingValue
 o debug
  public void debug()

All Packages  Class Hierarchy  This Package  Previous  Next  Index