OCCI Classes and Methods, 14 of 22

## Number Class

The `Number` class handles limited-precision signed base 10 numbers. A `Number` guarantees 38 decimal digits of precision. All positive numbers in the range displayed here can be represented to a full 38-digit precision:

```10^-130

```

and

```9.99999999999999999999999999999999999999*10^125

```

The range of representable negative numbers is symmetrical.

The number zero can be represented exactly. Also, Oracle numbers have representations for positive and negative infinity. These are generally used to indicate overflow.

The internal storage type is opaque and private. Scale is not preserved when `Number` instances are created.

`Number` does not support the concept of NaN and is not IEEE-754-85 compliant. `Number` does support +Infinity and -Infinity.

There are several variants of syntax:

Default constructor.

```Number();

Number(const Number &srcNum);

```

Translates a native long double into a `Number`. The `Number` is created using the precision of the platform-specific constant LDBL_DIG.

```Number(long double val);

```

Translates a native double into a `Number`. The `Number` is created using the precision of the platform-specific constant DBL_DIG.

```Number(double val);

```

Translates a native float into a `Number`. The `Number` is created using the precision of the platform-specific constant FLT_DIG.

```Number(float val);

```

Translates a native long into a `Number`.

```Number(long val);

```

Translates a native int into a `Number`.

```Number(int val);

```

Translates a native short into a `Number`.

```Number(short val);

```

Translates a native char into a `Number`.

```Number(char val);

```

Translates a native signed char into a `Number`.

```Number(signed char val);

```

Translates an native unsigned long into a `Number`.

```Number(unsigned long val);

```

Translates a native unsigned int into a `Number`.

```Number(unsigned int val);

```

Translates a native unsigned short into a `Number`.

```Number(unsigned short val);

```

Translates the unsigned character array into a `Number`.

```Number(unsigned char val);

```

Objects from the `Number` class can be used as standalone class objects in client side numerical computations. They can also be used to fetch from and set to the database.

The following code example demonstrates a `Number` column value being retrieved from the database, a bind using a `Number` object, and a comparison using a standalone `Number` object:

```/* Create a connection */
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Connection *conn = env->createConnection(user, passwd, db);

/* Create a statement and associate a select clause with it */
string sqlStmt = "SELECT department_id FROM DEPARTMENTS";
Statement *stmt = conn->createStatement(sqlStmt);

/* Execute the statement to get a result set */
ResultSet *rset = stmt->executeQuery();
while(rset->next())
{
Number deptId = rset->getNumber(1);
/* Display the department id with the format string 9,999 */
cout << "Department Id" << deptId.toText(env, "9,999");

/* Use the number obtained as a bind value in the following query */
stmt->setSQL("SELECT * FROM EMPLOYEES WHERE department_id = :x");
stmt->setNumber(1, deptId);
ResultSet *rset2 = stmt->executeQuery();
.
.
.
}
/* Using a Number object as a standalone and the operations on them */

/* Create a number to a double value */
double value = 2345.123;
Number nu1 (value);

/* Some common Number methods */
Number abs = nu1.abs();    /* absolute value */
Number sqrt = nu1.squareroot();    /* square root */

/* Cast operators can be used */
long lnum = (long) nu1;

/* Unary increment/decrement prefix/postfix notation */
nu1++;
--nu1;

/* Arithmetic operations */
Number nu2(nu1);

/* Assignment operators */
Number nu3;
nu3 = nu2;
nu2 = nu2 + 5.89;
Number nu4;
nu4 = nu1 + nu2;

/* Comparison operators */
if(nu1>nu2)
.
.
.
else if(nu1 == nu2)
.
.
.
```

### Summary of Number Methods

##### Table 8-14 Number Methods
Method Summary

Return the absolute value of the number.

Return the arcCosine of the number.

Return the arcSine of the number.

Return the arcTangent of the number.

Return the arcTangent2 of the input number `y` and this number `x`.

Return the smallest integral value not less than the value of the number.

Return the cosine of the number.

Return the natural exponent of the number.

Return the largest integral value not greater than the value of the number.

Return a Number derived from a `Bytes` object.

Return a Number from a given number string , format string and nls parameters specified.

Return the hyperbolic cosine of the number.

Return the hyperbolic sine of the number.

Return the hyperbolic tangent of the number.

Return the number raised to the integer value specified.

Check if `Number` is null.

Return the natural logarithm of the number.

Return the logarithm of the number to the base value specified.

Increment the `number by 1`.

Increment the `number by 1` .

Decrement the `number` by 1.

Decrement the n`umber` by 1.

Return the product of two `Number`s.

Return the quotient of two `Number`s.

Return the modulo of two `Number`s.

Return the sum of two `Number`s.

Return the negated value of `Number`.

Return the difference between two `Number`s.

Check if a number is less than an other number.

Check if a number is less than or equal to an other number.

Check if a number is greater than an other number.

Check if a number is greater than or equal to an other number.

Check if two numbers are equal.

Check if two numbers are not equal.

Assign one number to another.

Multiplication assignment.

Division assignment.

Modulo assignment.

Subtraction assignment.

Return `Number` converted to native char.

Return `Number` converted to native signed char.

Return `Number` converted to a native double.

Return `Number` converted to a native float.

Return `Number` converted to native integer.

Return `Number` converted to native long.

Return `Number` converted to a native long double.

Return `Number` converted to native short integer.

Return `Number` converted to an unsigned native char.

Return `Number` converted to an unsigned native integer.

Return `Number` converted to an unsigned native long.

Return `Number` converted to an unsigned native short integer.

Return `Number` raised to the power of another number specified.

Return `Number` rounded to digits of precision specified.

Return `Number` rounded to decimal place specified. Negative values are allowed.

Set `Number` to null.

Return a `Number` that is equivalent to the passed value `* 10^n`, where `n` may be positive or negative.

Return the sign of the value of the passed value: -1 for the passed value < 0, 0 for the passed value == 0, and 1 for the passed value > 0.

Return sine of the number.

Return the square root of the number.

Returns tangent of the number.

Return a `Bytes` object representing the `Number`.

Return the number as a string formatted based on the format and nls parameters.

Return a `Number` with the value truncated at `n` decimal place(s). Negative values are allowed.

## abs()

This method returns the absolute value of the `Number` object.

##### Syntax
```const Number abs() const;

```

## arcCos()

This method returns the arccosine of the `Number` object.

##### Syntax
```const Numberconst Number arcCos() const;

```

## arcSin()

This method returns the arcsine of the `Number` object.

##### Syntax
```const Number arcSin() const;

```

## arcTan()

This method returns the arctangent of the `Number` object.

##### Syntax
```const Number arcTan() const;

```

## arcTan2()

This method returns the arctangent of the `Number` object with the parameter specified. It returns atan2 ( y,x) where y is the parameter specified and x is the current number object.

##### Syntax
```const Number arcTan2(const Number &val) const
```
##### val

Number parameter y to the arcTangent function atan2(y,x) .

## ceil()

This method returns the smallest integer that is greater than or equal to the `Number` object.

##### Syntax
```const Number ceil() const;

```

## cos()

This method returns the cosine of the `Number` object.

##### Syntax
```const Number cos() const;

```

## exp()

This method returns the natural exponential of the `Number` object.

##### Syntax
```const Number exp() const;

```

## floor()

This method returns the largest integer that is less than or equal to the `Number` object.

##### Syntax
```const Number floor() const;

```

## fromBytes()

This method returns a `Number` object represented by the byte string specified.

##### Syntax
```void fromBytes(const Bytes &s);
```

A byte string.

## fromText()

This method returns a `Number` object derived from a string value.

##### Syntax
```void fromText(const Environment *envp,
const string &number,
const string &fmt,
const string &nlsParam = "");
```
##### envp

The OCCI environment.

##### number

The number string to be converted to a `Number` object.

Format string.

##### nlsParam

The nls parameters string. If `nlsParam` is specified, this determines the nls parameters to be used for the conversion. If `nlsParam` is not specified, the nls parameters are picked up from `envp`.

## hypCos()

This method returns the hypercosine of the `Number` object.

##### Syntax
```const Number hypCos() const;

```

## hypSin()

This method returns the hypersine of the `Number` object.

##### Syntax
```const Number hypSin() const;

```

## hypTan()

This method returns the hypertangent of the `Number` object.

##### Syntax
```const Number hypTan() const;

```

## intPower()

This method returns a `Number` whose value is the number object raised to the power of the value specified.

##### Syntax
```const Number intPower(int val) const;
```
##### val

Integer to whose power the number is raised.

## isNull()

This method tests whether the `Number` object is null. If the `Number` object is null, then true is returned; otherwise, false is returned.

##### Syntax
```bool isNull() const;

```

## ln()

This method returns the natural logorithm of the `Number` object.

##### Syntax
```const Number ln() const;

```

## log()

This method returns the logorithm of the `Number` object with the base provided by the parameter specified.

##### Syntax
```const Number log(const Number &val) const;
```
##### val

The base to be used in the logorithm calculation.

## operator++()

Unary `operator++()`. This method returns the `Number` object incremented by 1. This is a prefix operator.

##### Syntax
```Number& operator++();

```

## operator++()

Unary `operator++().` This method returns the `Number` object incremented by the integer specified. This is a postfix operator.

##### Syntax
```const Number operator++(int);

```

## operator--()

Unary `operator--()`. This method returns the `Number` object decremented by 1. This is a prefix operator.

##### Syntax
```Number& operator--();

```

## operator--()

Unary `operator--()`. This method returns the `Number` object decremented by the integer specified. This is a postfix operator.

##### Syntax
```const Number operator--(int);

```

## operator*()

This method returns the product of the parameters specified.

##### Syntax
```Number operator*(const Number &a,

const Number &b);
```
##### a, b

Numbers to be multiplied.

## operator/()

This method returns the quotient of the parameters specified.

##### Syntax
```Number operator/(const Number &dividend,
const Number &divisor);
```
##### dividend

The number to be divided.

##### divisor

The number to divide by.

## operator%()

This method returns the remainder of the division of the parameters specified.

##### Syntax
```Number operator%(const Number &a,
const Number &b);
```
##### a, b

Numbers which are operands in the modulo operation.

## operator+()

This method returns the sum of the parameters specified.

##### Syntax
```Number operator+(const Number &a,
const Number &b);
```

## operator-()

Unary `operator-()`. This method returns the negated value of the `Number` object.

##### Syntax
```const Number operator-();

```

## operator-()

This method returns the difference between the parameters specified.

##### Syntax
```Number operator-(const Number &subtrahend,
const Number &subtractor);
```
##### subtrahend

The number to be reduced.

##### subtractor

The number to be subtracted.

## operator<()

This method checks whether the first parameter specified is less than the second parameter specified. If the first parameter is less than the second parameter, then true is returned; otherwise, false is returned. If either parameter is equal to infinity, then false is returned.

##### Syntax
```bool operator<(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared .

## operator<=()

This method checks whether the first parameter specified is less than or equal to the second parameter specified. If the first parameter is less than or equal to the second parameter, then true is returned; otherwise, false is returned. If either `parameter` is equal to infinity, then false is returned.

##### Syntax
```bool operator<=(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared.

## operator>()

This method checks whether the first parameter specified is greater than the second parameter specified. If the first parameter is greater than the second parameter, then true is returned; otherwise, false is returned. If either parameter is equal to infinity, then false is returned.

##### Syntax
```bool operator>(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared .

## operator>=()

This method checks whether the first parameter specified is greater than or equal to the second parameter specified. If the first parameter is greater than or equal to the second parameter, then true is returned; otherwise, false is returned. If either parameter is equal to infinity, then false is returned.

##### Syntax
```bool operator>=(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared.

## operator==()

This method checks whether the parameters specified are equal. If the parameters are equal, then true is returned; otherwise, false is returned. If either parameter is equal to +infinity or -infinity, then false is returned.

##### Syntax
```bool operator==(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared.

## operator!=()

This method checks whether the first parameter specified is equal to the second parameter specified. If the parameters are not equal, true is returned; otherwise, false is returned.

##### Syntax
```bool operator!=(const Number &a,
const Number &b);
```
##### a, b

Numbers which are compared.

## operator=()

This method assigns the value of the parameter specified to the `Number` object.

##### Syntax
```Number& operator=(const Number &a);
```
##### a

The number to be assigned.

## operator*=()

This method multiplies the `Number` object by the parameter specified, and assigns the product to the `Number` object.

##### Syntax
```Number& operator*=(const Number &a);
```
##### a

A parameter of type `Number`.

## operator/=()

This method divides the `Number` object by the parameter specified, and assigns the quotient to the `Number` object.

##### Syntax
```Number& operator/=(const Number &a);
```
##### a

A parameter of type `Number`.

## operator%=()

This method divides the `Number` object by the parameter specified, and assigns the remainder to the `Number` object.

##### Syntax
```Number& operator%=(const Number &a);
```
##### a

A parameter of type `Number`.

## operator+=()

This method adds the Number object and the parameter specified, and assigns the sum to the `Number` object.

##### Syntax
```Number& operator+=(const Number &a);
```
##### a

A parameter of type `Number`.

## operator-=()

This method subtracts the parameter specified from the `Number` object, and assigns the difference to the `Number` object.

##### Syntax
```Number& operator-=(const Number &a);
```
##### a

A parameter of type `Number`.

## operator char()

This method returns the value of the Number object converted to a native char.

##### Syntax
```operator char() const;

```

## operator signed char()

This method returns the value of the Number object converted to a native signed char.

##### Syntax
```operator signed char() const;

```

## operator double()

This method returns the value of the `Number` object converted to a native double.

##### Syntax
```operator double() const;

```

## operator float()

This method returns the value of the `Number` object converted to a native float.

##### Syntax
```operator float() const;

```

## operator int()

This method returns the value of the `Number` object converted to a native int.

##### Syntax
```operator int()const;

```

## operator long()

This method returns the value of the `Number` object converted to a native long.

##### Syntax
```operator long() const;

```

## operator long double()

This method returns the value of the `Number` object converted to a native long double.

##### Syntax
```operator long double() const;

```

## operator short()

This method returns the value of the `Number` object converted to a native short integer.

##### Syntax
```operator short() const;

```

## operator unsigned char()

This method returns the value of the `Number` object converted to a native unsigned char.

##### Syntax
```operator unsigned char() const;

```

## operator unsigned int()

This method returns the value of the `Number` object converted to a native unsigned integer.

##### Syntax
```operator unsigned int() const;

```

## operator unsigned long()

This method returns the value of the `Number` object converted to a native unsigned long.

##### Syntax
```operator unsigned long() const;

```

## operator unsigned short()

This method returns the value of the `Number` object converted to a native unsigned short integer.

##### Syntax
```operator unsigned short() const;

```

## power()

This method returns the value of the `Number` object raised to the power of the value provided by the parameter specified.

##### Syntax
```const Number power(const Number &val) const;
```
##### val

The number to whose power this number has to be raised.

## prec()

This method returns the value of the `Number` object rounded to the digits of precision provided by the parameter specified.

##### Syntax
```const Number prec(int digits) const;
```
##### digits

The number of digits of precision.

## round()

This method returns the value of the `Number` object rounded to the decimal place provided by the parameter specified.

##### Syntax
```const Number round(int decplace) const;
```
##### decplace

The number of digits to the right of the decimal point.

## setNull()

This method sets the value of the `Number` object to null.

##### Syntax
```void setNull();

```

## shift()

This method returns the `Number` object multiplied by 10 to the power provided by the parameter specified.

##### Syntax
```const Number shift(int val) const;
```
##### val

An integer value.

## sign()

This method returns the sign of the value of the `Number` object. If the `Number` object is negative, then -1 is returned. If the `Number` object is equal to 0, then 0 is returned. If the `Number` object is positive, then 1 is returned.

##### Syntax
```const int sign() const;

```

## sin()

This method returns the sin of the `Number` object.

##### Syntax
```const Number sin();

```

## sqareroot()

This method returns the square root of the `Number` object.

##### Syntax
```const Number squareroot() const;

```

## tan()

This method returns the tangent of the `Number` object.

##### Syntax
```const Number tan() const;

```

## toBytes()

This method converts the `Number` object into a `Bytes` object. The bytes representation is assumed to be in length excluded format, that is, the `Byte.length()` method gives the length of valid bytes and the 0th byte is the exponent byte.

##### Syntax
```Bytes toBytes() const;

```

## toText()

This method converts the `Number` object to a formatted string based on the parameters specified.

##### Syntax
```string toText(const Environment *envp,
const string &fmt,
const string &nlsParam = "") const;
```
##### envp

The OCCI environment.

##### fmt

The format string.

##### nlsParam

The nls parameters string. If `nlsParam` is specified, this determines the nls parameters to be used for the conversion. If `nlsParam` is not specified, the nls parameters are picked up from `envp`.

## trunc()

This method returns the `Number` object truncated at the number of decimal places provided by the parameter specified.

##### Syntax
```const Number trunc(int decplace) const;
```
##### decplace

The number of places to the right of the decimal place at which the value is to be truncated.