rwlogo
SourcePro 11.1

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWDecimalPortable Class Reference
[MiscellaneousDecimal Numbers]

Represents an arbitrary precision decimal fraction, providing maximum portability. More...

#include <rw/tools/decport.h>

Inheritance diagram for RWDecimalPortable:
RWDecimalBase

List of all members.

Public Member Functions

 RWDecimalPortable ()
 RWDecimalPortable (const char *input)
 RWDecimalPortable (long intPart)
 operator RWCString () const
RWCString asString () const
RWCString asString (const RWLocale &loc) const
bool isNumber () const
void trimZeros ()
size_t binaryStoreSize () const
unsigned hash () const
void restoreFrom (RWvistream &vis)
void restoreFrom (RWFile &file)
void saveOn (RWvostream &vos) const
void saveOn (RWFile &file) const

Friends

RWDecimalPortable round (const RWDecimalPortable &, RWssize_t, RoundingMethod)
double toDouble (const RWDecimalPortable &)
long double toLongDouble (const RWDecimalPortable &)
RWDecimalPortable operator- (const RWDecimalPortable &)
RWDecimalPortable operator+ (const RWDecimalPortable &, const RWDecimalPortable &)
RWDecimalPortable operator* (const RWDecimalPortable &, const RWDecimalPortable &)
bool operator== (const RWDecimalPortable &x, const RWDecimalPortable &y)
bool operator< (const RWDecimalPortable &x, const RWDecimalPortable &y)

Related Functions

(Note that these are not member functions.)



typedef unspecified_type RWssize_t
std::ostream & operator<< (std::ostream &ostrm, const RWDecimalPortable &x)
std::istream & operator>> (std::istream &strm, RWDecimalPortable &n)
RWDecimalPortable operator- (const RWDecimalPortable &x, const RWDecimalPortable &y)
bool operator!= (const RWDecimalPortable &x, const RWDecimalPortable &y)
bool operator>= (const RWDecimalPortable &x, const RWDecimalPortable &y)
bool operator> (const RWDecimalPortable &x, const RWDecimalPortable &y)
bool operator<= (const RWDecimalPortable &x, const RWDecimalPortable &y)

Detailed Description

RWDecimalPortable represents an arbitrary precision decimal fraction.

The RWDecimalPortable class is designed to provide maximum portability. However, its portability is gained at the expense of speed and power. For example, RWDecimalPortable does not support all of the functionality of the other decimal classes in the Currency Module. In most cases we recommend that you use another of the decimal classes from the Currency Module, but in situations in which the portability of a number is paramount, RWDecimalPortable is useful.

When constructing an RWDecimalPortable from a string, the constructor parses the initial characters of the string until the first non-digit, behaving similarly to Standard C Library's strtod() function. For example, a string "12E3" creates an RWDecimalPortable value of 12000.

If an RWDecimalPortable is provided an invalid string, either in the constructor or through assignment, it does not throw an exception. Use isNumber() to determine if the object is valid.

 RWDecimalPortable a("555AAA");
 a.isNumber(); // returns true
 
 RWDecimalPortable b;
 b = "A555AAA";
 b.isNumber(); // returns false (NAN)

Note that:

Synopsis

 #include <rw/tools/decport.h>
 
 RWDecimalPortable dec;     // construct a decimal == 0
 dec = "1.23";              // construct a decimal == 1.23

Constructor & Destructor Documentation

RWDecimalPortable::RWDecimalPortable (  )  [inline]

The default constructor creates a value initialized to zero (0).

RWDecimalPortable::RWDecimalPortable ( const char *  input  ) 

Parses the initial portion of input formatted as a decimal number up to the end of the string, or the first non-decimal character, whichever comes first. The parse behavior is locale-dependent (for decimal points, thousands separator, grouping, etc). If no locale is specified, the default locale is used, and parsing behavior will be defined by that locale, creating possibly unexpected results. To ensure predictable and expected behavior, the program should explicitly specify the locale before using this constructor, and input strings should be formatted according the numeric string facets for that locale.

For more information on conversions between strings and numbers, see the section on numbers in the internationalization chapter of the Essential Tools Module User's Guide.

RWDecimalPortable::RWDecimalPortable ( long  intPart  )  [inline]

Constructs a value with intPart as the part before the decimal point.


Member Function Documentation

RWCString RWDecimalPortable::asString ( const RWLocale loc  )  const

Returns self as an RWCString using the provided RWLocale instance for numeric formatting. For example, an English locale could return strings such as -23.21, 0.32, or 432.

RWCString RWDecimalPortable::asString ( void   )  const [inline]

Returns self as an RWCString using the global locale as determined by the static member function RWLocale::global() for numeric formatting. For example, an English locale could return strings such as -23.21, 0.32, or 432.

size_t RWDecimalPortable::binaryStoreSize (  )  const [inline]

Returns the number of bytes required to store self using the saveOn() methods.

unsigned RWDecimalPortable::hash (  )  const [inline]

Returns a value suitable for hashing.

bool RWDecimalPortable::isNumber (  )  const [inline]

Returns false if self represents a NaN, a missing value, or a NULL; otherwise returns true.

Note:
In this instance, the mathematical rather than the RDBMS meaning of NULL is intended. Please see RWDBNullIndicator.
RWDecimalPortable::operator RWCString (  )  const [inline]

Returns self as an RWCString. Format is, for example -23.21 or 0.32 or 432.

void RWDecimalPortable::restoreFrom ( RWFile file  ) 

Reads file, replacing the contents of self.

void RWDecimalPortable::restoreFrom ( RWvistream vis  ) 

Reads vis, replacing the contents of self.

void RWDecimalPortable::saveOn ( RWFile file  )  const

Writes the contents of self to file.

void RWDecimalPortable::saveOn ( RWvostream vos  )  const

Writes the contents of self to vos.

void RWDecimalPortable::trimZeros (  )  [inline]

Removes leading zeros before self's decimal point and trailing zeros after.


Friends And Related Function Documentation

bool operator!= ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [related]

Relational operator. Returns true if x is not equal to y.

RWDecimalPortable operator* ( const RWDecimalPortable ,
const RWDecimalPortable  
) [friend]

Rudimentary multiplication operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator+ ( const RWDecimalPortable ,
const RWDecimalPortable  
) [friend]

Rudimentary addition operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator- ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [related]

Rudimentary subtraction operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

RWDecimalPortable operator- ( const RWDecimalPortable x  )  [friend]

Rudimentary negation operator with minimal efficiency. For efficiency, use one of the decimal classes of the SourcePro Analysis product's Currency Module.

bool operator< ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [friend]

Relational operator. Returns true if x is less than y.

std::ostream & operator<< ( std::ostream &  ostrm,
const RWDecimalPortable x 
) [related]

Writes an RWDecimalPortable to an output stream.

bool operator<= ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [related]

Relational operator. Returns true if x is less than or equal to y.

bool operator== ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [friend]

Relational operator. Returns true if x is equal to y.

bool operator> ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [related]

Relational operator. Returns true if x is greater than y.

bool operator>= ( const RWDecimalPortable x,
const RWDecimalPortable y 
) [related]

Relational operator. Returns true if x is greater than or equal to y.

std::istream & operator>> ( std::istream &  strm,
RWDecimalPortable n 
) [related]

Reads an RWDecimalPortable from an input stream.

RWDecimalPortable round ( const RWDecimalPortable ,
RWssize_t  ,
RoundingMethod   
) [friend]

Returns an RWDecimalPortable which is the result of rounding self according to the applied specifications.

typedef unspecified_type RWssize_t [related]

An unspecified signed integer type.

double toDouble ( const RWDecimalPortable  )  [friend]

Returns a double which approximates the value of dp.

long double toLongDouble ( const RWDecimalPortable  )  [friend]

Returns a long double which approximates the value of dp.


© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.