RWDecimalPortable RWDecimalBase
Data Types | |
enum RoundingMethod |
#include <rw/decport.h> RWDecimalPortable dec; // construct a decimal == 0 dec = "1.23"; // construct a decimal == 1.23
RWDecimalPortable represents an arbitrary precision decimal fraction.
The RWDecimalPortable class is designed to provide maximum portability. The portability achieved in RWDecimalPortable 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 most cases we recommend that you use another of the decimal classes, but in situations in which the portability of a number is paramount, RWDecimalPortable is useful.
RWDecimalBase contains the following enum, used by the round() method:
enum RoundingMethod { PLAIN = 0, UP = 1, DOWN = 2, BANKERS = 3, TRUNCATE = 2 };
Rounding methods are defined in Table 5 below.
Method | Description | 1.25 | 1.35 | 1.251 |
PLAIN |
Rounds away from zero on a tie |
1.3 |
1.4 |
1.3 |
UP |
Always rounds away from zero |
1.3 |
1.4 |
1.3 |
DOWN |
Always rounds toward zero |
1.2 |
1.3 |
1.2 |
TRUNCATE |
Same as DOWN |
1.2 |
1.3 |
1.2 |
BANKERS |
On a tie, round so last digit is even |
1.2 |
1.4 |
1.3 |
RWDecimalPortable();
The default constructor creates a value initialized to zero(0).
RWDecimalPortable(const char* input);
Parses input, which must be recognizable as a decimal number. Embedded commas to separate groups of digits are allowed. Negation may be expressed by a minus sign or with parentheses.
RWDecimalPortable(long intPart);
Constructs a value with intPart as the part before the decimal point.
operator RWCString();
Returns self as an RWCString. Format is, for example -23.21 or 0.32 or 432.
virtual RWspace binaryStoreSize() const;
Returns the number of bytes required to store self using the saveOn() methods.
friend unsigned hash() const;
Returns a value suitable for hashing.
RWBoolean isNumber() const;
Returns FALSE if self represents a NaN, a missing value, or a NULL, otherwise TRUE.
friend void restoreFrom(RWFile& file);
Reads file, replacing the contents of self.
friend void restoreFrom(RWvistream& vis);
Reads vis, replacing the contents of self.
friend void saveOn(RWFile& file) const;
Writes the contents of self to file.
friend void saveOn(RWvostream& vos) const;
Writes the contents of self to vos.
void trimZeros();
Removes leading zeros before self's decimal point and trailing zeros after.
RWDecimalPortable round(const RWDecimalPortable&, int digits, RoundingMethod = RWDecimalBase::PLAIN);
Returns an RWDecimalPortable which is the result of rounding self according to the applied specifications.
double toDouble(const RWDecimalPortable&);
Returns a double which approximates the value of self.
RWDecimalPortable operator-(const RWDecimalPortable&); RWDecimalPortable operator+(const RWDecimalPortable&, const RWDecimalPortable&); RWDecimalPortable operator-(const RWDecimalPortable&, const RWDecimalPortable&); RWDecimalPortable operator*(const RWDecimalPortable&, const RWDecimalPortable&);
Rudimentary math functions. These are not very efficient. For efficiency, use one of the decimal classes of Money.h++.
RWBoolean operator==(const RWDecimalPortable& x, const RWDecimalPortable& y); RWBoolean operator>=(const RWDecimalPortable& x, const RWDecimalPortable& y); RWBoolean operator!=(const RWDecimalPortable& x, const RWDecimalPortable& y); RWBoolean operator<(const RWDecimalPortable& x, const RWDecimalPortable& y); RWBoolean operator>(const RWDecimalPortable& x, const RWDecimalPortable& y); RWBoolean operator<=(const RWDecimalPortable& x, const RWDecimalPortable& y);
Relational operators.
ostream& operator<<(ostream&, const RWDecimalPortable&);
Writes an RWDecimalPortable to an output stream.
ostream& operator>>(istream&, RWDecimalPortable&);
Reads an RWDecimalPortable from an input stream.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.