Does not inherit
asString() Decimal() decimalSeparator() hash() |
isNumber() isZero() missing NaN |
null numSignificantDigits() operator *=() operator+=() |
operator-=() precision() scale() trimZeros() |
#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)==stdstring(y) since "1.200"=="1.2".
const Decimal missing;
Prototype non-numeric value. Use this to set an rwsf::Decimal to a non-numeric value or to test for a specific non-numeric value.
const Decimal NaN;
Prototype non-numeric value. Use this to set an rwsf::Decimal to a non-numeric value or to test for a specific non-numeric value.
const Decimal null;
Prototype non-numeric value. Use this to set an rwsf::Decimal to a non-numeric value or to test for a specific non-numeric value.
Decimal(const char * s);
Constructs an rwsf::Decimal from the null-terminated character string s. 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(const std::string & s);
Constructs an rwsf::Decimal from the null-terminated character string s. 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);
Parses input or sets to NaN if unparseable.
Decimal(int);
Parses input or sets to NaN if unparseable.
Decimal();
Constructs an rwsf::Decimal with a value of null.
std::string decimalSeparator();
The decimal point symbol.
std::string asString() const;
Format is, e.g., -23.21 or 0.32 or 432.
std::string asString(const rwsf::Locale &) const;
Format is, e.g., -23.21 or 0.32 or 432.
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();
Returns true if the Decimal represents a 0 value, false otherwise.
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 trimZeros();
Remove leading zeros before decimal point and trailers after.
const Decimal & operator *=(const Decimal & rhs);
Arithmetic operator. 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.
const Decimal & operator+=(const Decimal & rhs);
Arithmetic operator. 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.
const Decimal & operator-=(const Decimal & rhs);
Arithmetic operator. 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.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.