rwsf::Decimal RWDecimalBase
#include <rwsf/core/Decimal.h>
This class represents an arbitrary precision decimal fraction. The representation is not exposed via member functions for accessing the strings representing the pieces before and after the decimal. This is done because it might make sense to one day replace this implementation with an arbitrary precision integer-based implementation.
The concept of trailing zeros after the decimal place is supported. If you construct an rwsf::Decimal using the string constructor and have trailing zeros (e.g., 1.200), then you are guaranteed that the string conversion operator will return a string with these trailing zeros. Rounding supports the concept of trailing zeros, so round("1.2",2) yields 1.20. The math functions (+-*) truncate trailing zeros. Use trimZeros() to strip off the excess zeros. Note that because trailing zeroes are allowed the relation x==y does not guarantee that std::string(x)==std::string(y) since "1.200"=="1.2".
Decimal();
Constructs an rwsf::Decimal with a value of null.
Decimal(const Decimal&);
Copy constructor. Constructs an rwsf::Decimal that is a copy of the argument.
Decimal(const char *); Decimal(const std::string&);
Constructs an rwsf::Decimal from the null-terminated character string *. Since we write numbers using base 10, and the rwsf::Decimal class stores numbers using base 10, the number constructed is an exact representation of the string. If the string cannot be successfully parsed as a number, the rwsf::Decimal is initialized to null. If the number in the string cannot be exactly represented (for example, it has too many significant digits) then the appropriate error handler (either the inexact or overflow handler) is called. The string may contain embedded commas to separate groups of digits and may have a leading dollar sign. Negatives can be indicated with a negative sign or by using parentheses.
Decimal(long); Decimal(int);
Parses input or sets to NaN if unparseable.
std::string asString()const; std::string asString(const rwsf::Locale&) const;
Format is, e.g., -23.21 or 0.32 or 432.
static std::string decimalSeparator(const rwsf::Locale&);
The decimal point symbol.
unsigned hash() const;
Returns a value suitable for hashing.
bool isNumber() const;
Returns TRUE if self represents a decimal fraction; returns FALSE if self is not a representation of a number; for example, if self is a null or missing value.
bool isZero();
Format is, e.g., -23.21 or 0.32 or 432.
size_t numSignificantDigits() const;
Number of digits. Does not count leading zeros (for numbers < 1), minus signs, or decimal points.
size_t precision() const;
Precision is to total number of digits in the number.
size_t scale() const;
Scale is the number of digits to the right of the decimal point.
void setState(State);
State state() const;
static std::string thousandsSeparator(const rwsf::Locale&);
void trimZeros();
Remove leading zeros before decimal point and trailers after.
Decimal& operator=(const Decimal&);
Sets the value of self equal to the value of the argument.
const Decimal& operator-=(const Decimal &rhs); const Decimal& operator+=(const Decimal &rhs); const Decimal& operator*=(const Decimal &rhs);
Arithmetic operators. Performs the operation between self and the argument, and then stores the results in self. If the resulting operation causes loss of precision or overflow in the result, the appropriate error handler will be called before the function returns.
RWDecimal missing; RWDecimal NaN; RWDecimal null;
These are the prototype non-numeric values. Use these to set an rwsf::Decimal to a non-numeric value or to test for a specific non-numeric value.
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark of Quovadx, 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.