HydraExpress™ C++ 2020 |
HydraExpress™ C++ API Reference Guide |
Product Documentation: HydraExpress C++ Documentation Home |
Represents an arbitrary precision decimal fraction. More...
#include <rwsf/core/Decimal.h>
Public Member Functions | |
Decimal () | |
Decimal (const char *s) | |
Decimal (const std::string &s) | |
Decimal (long before) | |
Decimal (int before) | |
std::string | asString () const |
std::string | asString (const rwsf::Locale &) const |
unsigned | hash () const |
bool | isNumber () const |
bool | isZero () |
size_t | numSignificantDigits () const |
const Decimal & | operator*= (const Decimal &rhs) |
const Decimal & | operator+= (const Decimal &rhs) |
const Decimal & | operator-= (const Decimal &rhs) |
size_t | precision () const |
size_t | scale () const |
void | trimZeros () |
Static Public Member Functions | |
static std::string | decimalSeparator (const rwsf::Locale &loc) |
static std::string | decimalSeparator () |
static std::string | thousandsSeparator (const rwsf::Locale &loc) |
static std::string | thousandsSeparator () |
Static Public Attributes | |
static const Decimal | NaN |
static const Decimal | null |
Related Functions | |
(Note that these are not member functions.) | |
Decimal | round (const Decimal &input, long digits, DecimalBase::RoundingMethod method) |
Additional Inherited Members | |
Public Types inherited from rwsf::DecimalBase | |
enum | RoundingMethod { PLAIN, UP, DOWN, BANKERS, TRUNCATE } |
This class represents an arbitrary precision decimal fraction. Trailing zeros and significant digits are maintained in the created Decimal object.
Several functions are available to perform mathematical operations on the Decimal object, including arithmetic, rounding, significant digits, and conversion to string. All valid operands follow standard mathematical rules in arithmetic and rounding operations.
Significant digits (aka significant figures or "sig figs") are supported and are calculated according to the mathematical definition:
[0]*N*.N*
, where N can be the digits 0-9, the number of significant digits is equal to the number of N digits. This is essentially the total number of digits minus the number of leading zeroes.NaN (Not a Number) and null entities are also supported:
0
. 0
is a valid, discrete integer. A null Decimal is more like a blank placeholder.2.345
cannot be represented with a precision of 2
. A precision of 4
would be needed for this to be a valid Decimal object.)These non-number entities follow standard mathematical guidelines when used in arithmetic operations:
rwsf::Decimal::Decimal | ( | ) |
Constructs an rwsf::Decimal with a value of null
.
rwsf::Decimal::Decimal | ( | const char * | s | ) |
Constructs an rwsf::Decimal from the null-terminated character string s. Acceptable inputs consist of:
Here are some other qualifications about the input:
rwsf::Decimal::Decimal | ( | const std::string & | s | ) |
Constructs an rwsf::Decimal from the null-terminated character string s. Acceptable inputs consist of:
Here are some other qualifications about the input:
rwsf::Decimal::Decimal | ( | long | before | ) |
Constructs an rwsf::Decimal by parsing the input long before. This construction always succeeds. That is, a valid long
reliably results in a valid rwsf::Decimal.
rwsf::Decimal::Decimal | ( | int | before | ) |
Constructs an rwsf::Decimal by parsing the input integer before. This construction always succeeds. That is, a valid int
reliably results in a valid RWDecimal.
std::string rwsf::Decimal::asString | ( | ) | const |
Returns the stored decimal value as a string. The format is standard, e.g., -23.21 or 0.32 or 432.
std::string rwsf::Decimal::asString | ( | const rwsf::Locale & | ) | const |
Returns the stored decimal value as a string. The format is standard, e.g., -23.21 or 0.32 or 432.
|
static |
Returns the decimal separator (e.g., "." in the U.S., "," in Europe) for the given Locale loc.
|
static |
Returns the decimal separator (e.g., "." in the U.S., "," in Europe) for the local Locale.
unsigned rwsf::Decimal::hash | ( | ) | const |
Returns a value suitable for hashing.
bool rwsf::Decimal::isNumber | ( | ) | const |
bool rwsf::Decimal::isZero | ( | ) |
Returns true
if the Decimal represents a 0
value, false
otherwise.
size_t rwsf::Decimal::numSignificantDigits | ( | ) | const |
Returns the number of significant digits (also known as significant figures) in the stored decimal (See class description for more information on significant digits.)
Arithmetic operator. Performs the operation between self and the rhs, and then stores the results in self.
Arithmetic operator. Performs the operation between self and the rhs, and then stores the results in self.
Arithmetic operator. Performs the operation between self and the rhs, and then stores the results in self.
size_t rwsf::Decimal::precision | ( | ) | const |
Returns the floating point precision of the stored decimal. This is equal to the number of digits in the decimal value.
size_t rwsf::Decimal::scale | ( | ) | const |
Returns the number of digits to the right of the decimal point.
|
static |
Returns the thousands separator (e.g., "," in the U.S., "." in Europe) for the given Locale loc.
|
static |
Returns the thousands separator (e.g., "," in the U.S., "." in Europe) for the local Locale.
void rwsf::Decimal::trimZeros | ( | ) |
Removes any leading zeros before the first non-zero number, and any trailing zeros after the last non-zero number.
|
related |
Rounds the floating-point decimal input to the nearest integer based on the rounding rule given in method (See rwsf::DecimalBase::RoundingMethod for the description of the different rounding rules available).
round("1.2",2)
yields 1.20
.
|
static |
A built-in constant to help with comparisons, tests, or to set up non-numeric values.
|
static |
A built-in constant to help with comparisons, tests, or to set up non-numeric values.
Copyright © 2020 Rogue Wave Software, Inc. All Rights Reserved. |