To provide maximum precision, the Number class represents its value as a string internally. Using a floating-point number would lose precision because Oracle NUMBER types have a decimal internal representation. When an integer or floating-point value must be retrieved from the object, lng() and dbl() can be used.
Figure 2-3. class Number
namespace Oracle
{
class Number: public Nullable
{
public:
// constructors/destructor
Number();
Number(const int);
Number(const long);
Number(const double);
Number(const Number&);
virtual ~Number();
// accessors
virtual string str() const;
virtual string str(const string&) const;
virtual string str(const string&, const Format&) const;
virtual string sql_str() const;
virtual long lng() const;
virtual long lng(const long) const;
virtual double dbl() const;
virtual double dbl(const double) const;
virtual int sqlt() const;
virtual int maxsize() const;
// operators
Number& operator=(const int);
Number& operator=(const long);
Number& operator=(const double);
Number& operator=(const Number&);
Number& operator+=(const Number&);
Number& operator-=(const Number&);
Number& operator*=(const Number&);
Number& operator/=(const Number&);
bool operator==(const Number&);
bool operator!=(const Number&);
bool operator<(const Number&);
bool operator<=(const Number&);
bool operator>(const Number&);
bool operator>=(const Number&);
protected:
// implementors
virtual void* data() const;
};
ostream& operator<<(ostream&, const Number&);
const bool operator==(const Number&, const Number&);
}
Oracle::Number operator+(const Oracle::Number&, const Oracle::Number&);
Oracle::Number operator-(const Oracle::Number&, const Oracle::Number&);
Oracle::Number operator*(const Oracle::Number&, const Oracle::Number&);
Oracle::Number operator/(const Oracle::Number&, const Oracle::Number&);Number(void);
Number(const double initial_value);
Number(const Number& initial_value);
Number(const Nullable& initial_value);
A Number object may be initialized to a double, another Number, or as a Nullable.
Number& operator=(const Number& new_value);
Number& operator=(const Nullable& new_value);
Number& operator=(const long new_value);
Number& operator=(const double new_value);
A Number object may be assigned a long, a double or another Nullable-derived object.