BPS C++ API  2.24.4
BpsDecimal Class Reference

A class for decimal arithmetics. More...

#include <bpsdecimal.h>

Public Member Functions

BpsDecimal abs () const
 
 BpsDecimal ()
 The default constructor initializes the value to NaN.
 
 BpsDecimal (const BpsDecimal &aOther)
 The copy constructor. More...
 
 BpsDecimal (const char *aString)
 Construct from a decimal string representation. More...
 
 BpsDecimal (const QByteArray &aString)
 Construct from a decimal string representation. More...
 
 BpsDecimal (const QString &aString)
 Construct from a decimal string representation. More...
 
 BpsDecimal (const QVariant &aVariant)
 Construct from a QVariant. More...
 
 BpsDecimal (double aValue)
 Construct from a double value. More...
 
 BpsDecimal (qint32 aValue)
 Construct from a signed 32 bit integer value. More...
 
 BpsDecimal (qlonglong aValue)
 Construct from a 64 bit signed integer value. More...
 
 BpsDecimal (quint32 aValue)
 Construct from a unsigned 32 bit integer value. More...
 
 BpsDecimal (qulonglong aValue)
 Construct from a 64 bit unsigned integer value. More...
 
BpsDecimal ceil () const
 If the value is not integer, round up to next integer (towards +Infinity). More...
 
BpsDecimal div (const BpsDecimal &aOther) const
 Divides this value by the other value and returns the integer part of the result. More...
 
BpsDecimal down () const
 If the value is not integer, round down to next integer (towards 0). More...
 
BpsDecimal exp () const
 Calculate e to the power of this value and return the result. More...
 
BpsDecimal floor () const
 If the value is not integer, round down to next integer (towards -Infinity). More...
 
bool isFinite () const
 Check if value is neither infinite nor a NaN. More...
 
bool isInfinite () const
 Check if value is infinite. More...
 
bool isInteger () const
 Check if value is finite and has exponent=0. More...
 
bool isNaN () const
 Check if value is not a number. More...
 
bool isNegative () const
 Check if value is negative. More...
 
BpsDecimal ln () const
 Calculate the natural logarithm (to base e) of this value and return the result. More...
 
BpsDecimal log10 () const
 Calculate the logarithm to base ten of this value and return the result. More...
 
BpsDecimal max (const BpsDecimal &aOther) const
 Compare this value with the other and return the larger (nearer towards +Infinity). More...
 
BpsDecimal min (const BpsDecimal &aOther) const
 Compare this value with the other and return the smaller (nearer towards -Infinity). More...
 
 operator QVariant () const
 Automatic conversion to QVariant. More...
 
bool operator!= (const BpsDecimal &aOther) const
 Compare with other value for un-equality. More...
 
BpsDecimal operator% (const BpsDecimal &aOther) const
 Integer divide by other value and return remainder as result. More...
 
BpsDecimaloperator%= (const BpsDecimal &aOther)
 Integer divide by other value and set remainder as value. More...
 
BpsDecimal operator* (const BpsDecimal &aOther) const
 Multiply with other value and return result. More...
 
BpsDecimaloperator*= (const BpsDecimal &aOther)
 Multiply with other value. More...
 
BpsDecimal operator+ (const BpsDecimal &aOther) const
 Add two values and return result. More...
 
BpsDecimaloperator++ ()
 Prefix increment the value by one. More...
 
BpsDecimal operator++ (int)
 Postfix increment the value by one. More...
 
BpsDecimaloperator+= (const BpsDecimal &aOther)
 Add other value. More...
 
BpsDecimal operator- (const BpsDecimal &aOther) const
 Subtract second value and return result. More...
 
BpsDecimaloperator-- ()
 Prefix decrement the value by one. More...
 
BpsDecimal operator-- (int)
 Postfix decrement the value by one. More...
 
BpsDecimaloperator-= (const BpsDecimal &aOther)
 Subtract second value. More...
 
BpsDecimal operator/ (const BpsDecimal &aOther) const
 Divide by other value and return result. More...
 
BpsDecimaloperator/= (const BpsDecimal &aOther)
 Divide by other value. More...
 
bool operator< (const BpsDecimal &aOther) const
 Compare if less than other value. More...
 
bool operator<= (const BpsDecimal &aOther) const
 Compare if less than or equal to other value. More...
 
BpsDecimaloperator= (const BpsDecimal &aOther)
 Assign value from an other decimal. More...
 
BpsDecimaloperator= (const char *aString)
 Assign value from a string. More...
 
BpsDecimaloperator= (const QByteArray &aString)
 Assign value from a string. More...
 
BpsDecimaloperator= (const QString &aString)
 Assign value from a string. More...
 
BpsDecimaloperator= (const QVariant &aVariant)
 Assign value from a QVariant. More...
 
BpsDecimaloperator= (double aOther)
 Assign value from a double. More...
 
BpsDecimaloperator= (qint32 aOther)
 Assign value from a 32 bit signed integer. More...
 
BpsDecimaloperator= (qlonglong aOther)
 Assign value from a 64 bit signed integer. More...
 
BpsDecimaloperator= (quint32 aOther)
 Assign value from a 32 bit unsigned integer. More...
 
BpsDecimaloperator= (qulonglong aOther)
 Assign value from a 64 bit unsigned integer. More...
 
bool operator== (const BpsDecimal &aOther) const
 Compare with other value for equality. More...
 
bool operator> (const BpsDecimal &aOther) const
 Compare if greater than other value. More...
 
bool operator>= (const BpsDecimal &aOther) const
 Compare if greater than or equal to other value. More...
 
BpsDecimal power (const BpsDecimal &aOther) const
 Raises this value to the power of the other value and returns the result. More...
 
BpsDecimal rounded (int aDecPlaces) const
 Round to an number of decimal places. More...
 
BpsDecimal sqrt () const
 Calculate the square root of this value and return the result. More...
 
double toDouble () const
 Get the value as double. More...
 
qint32 toInt () const
 Get the value as signed 32 bit integer. More...
 
qlonglong toLongLong () const
 Get the value as 64 bit signed integer. More...
 
QString toString () const
 Converts a decimal value to a string. More...
 
QString toString (int aDecPlaces, int aMaxSize=36) const
 Converts a decimal value to a string of format [-]9.9. More...
 
quint32 toUInt () const
 Get the value as unsigned 32 bit integer. More...
 
qulonglong toULongLong () const
 Get the value as 64 bit unsigned integer. More...
 
QVariant toVariant () const
 Explicit conversion to QVariant. More...
 
BpsDecimal up () const
 If the value is not integer, round up to next integer (away from 0). More...
 

Static Public Member Functions

static BpsDecimal fromString (const char *aString, bool *aOk=0)
 Convert a string to a decimal value. More...
 
static BpsDecimal fromString (const QByteArray &aString, bool *aOk=0)
 Convert a string to a decimal value. More...
 
static BpsDecimal fromString (const QString &aString, bool *aOk=0)
 Convert a string to a decimal value. More...
 
static int metaType ()
 
static BpsDecimal Pi ()
 

Related Functions

(Note that these are not member functions.)

BPSCORE_EXPORT BpsDecimal operator- (const BpsDecimal &aValue)
 Unary prefix minus operator. More...
 
BPSCORE_EXPORT QDataStreamoperator<< (QDataStream &aStream, const BpsDecimal &aDecimal)
 Write the binary code of the decimal value to a data stream. More...
 
BPSCORE_EXPORT QDebug operator<< (QDebug aDebug, const BpsDecimal &aDecimal)
 Write the string representation of a decimal value to a debug stream. More...
 
BPSCORE_EXPORT QTextStreamoperator<< (QTextStream &aStream, const BpsDecimal &aDecimal)
 Write the string representation of the decimal value to a text stream. More...
 
BPSCORE_EXPORT std::ostream & operator<< (std::ostream &aStream, const BpsDecimal &aDecimal)
 Write the string representation of the decimal value to a std::ostream. More...
 
BPSCORE_EXPORT QDataStreamoperator>> (QDataStream &aStream, BpsDecimal &aDecimal)
 Read the binary code of the decimal value from a data stream. More...
 
BPSCORE_EXPORT uint qHash (const BpsDecimal &aValue, uint aSeed)
 Returns a hash value, as required by QHash or QSet. More...
 

Detailed Description

A class for decimal arithmetics.

The arithmetic of the standard floating point values is mathematically correct, however for many applications the results are inconvenient. It becomes then an issue when real (non-integer) numbers are involved in calculations:

double x1 = 1000.43;
double y1 = 1000;
qDebug() << (x1 - y1); // output: 0.42999999999995

Despite the result your computer is not broken, nor does it calculate inexact. The reason for this surprising output is that standard floating point works binary and with a finite number of digits, and there is a difference when the last digit must be rounded in calculations. Often you won't notice a delta like in the example above, but because it happens and gets multiplied with the number of operations, it's a serious problem even if the final result is rounded to few decimal places and so seems correct. But one day there could be a case where it is not.

And now the same calculation with the decimal class:

BpsDecimal x2 = 1000.43;
BpsDecimal y2 = 1000;
qDebug() << (x2 - y2); // output: 0.43
A class for decimal arithmetics.
Definition: bpsdecimal.h:87

USAGE HINTS

In calculations where a BpsDecimal is present, the other operand will automatically be converted to a BpsDecimal, and so the term and finally the overall result is a BpsDecimal:

BpsDecimal x = -30;
BpsDecimal y = x + 5 * 10;
// The term 5 * 10 evaluates to integer 50, but then before adding it to x, the intermediate
// result is converted to BpsDecimal, and so the addition is done in decimal arithmetic.

While decimal arithmetic is best suited for commercial or financial purposes, binary arithmetic is faster because it is the native number representation for computers and is handled by hardware floating point processors. Decimal arithmetic would perform bad for heavy number crunching like in graphic libraries for example. (No rule without exception however: mainframes have decimal hardware processors, but you will most likely not use mainframes as client PC's).

QVARIANT INTEGRATION

BpsDecimal is integrated to QVariant to enable QDebug output, conversion to string and regular numerics, and to compare for equality:

QVariant v1(BpsDecimal(-123.567));
QVariant v2(BpsDecimal(-123.567));
QVariant v3(BpsDecimal(23.567));
bool ok;
qDebug() << v1 << BpsDecimal(v1); // QVariant(BpsDecimal, -123.567) -123.567
qDebug() << v2.toString(); // "-123.567"
qDebug() << v3.toDouble(&ok) << ok; // 23.567 true
qDebug() << v1.toInt(&ok) << ok; // -123 true
qDebug() << v1.toUInt(&ok) << ok; // 0 false
qDebug() << v1.toLongLong(&ok) << ok; // -123 true
qDebug() << v1.toULongLong(&ok) << ok; // 0 false
qDebug() << v3.toULongLong(&ok) << ok; // 23 true
qDebug() << (v1 == v2) << (v1 != v2); // true false
qDebug() << (v1 == v3) << (v1 != v3); // false true
BpsDecimal()
The default constructor initializes the value to NaN.

Also, BpsDecimal can be streamed by QMetaType::load() and QMetaType::save(), which is used for example when QVariant is loaded or saved by QSettings.

IMPLEMENTATION AND CREDITS

BpsDecimal uses IBM's decNumber library to implement a numeric variable according to the General Decimal Arithmetic Specification in ANSI C. This specification defines a decimal arithmetic which meets the requirements of commercial, financial, and human-oriented applications. It also matches the decimal arithmetic in the IEEE 754 Standard for Floating Point Arithmetic.

BpsDecimal encapsulates decQuad and uses decimal128, a 128-bit decimal floating-point representation, to provide 34 decimal digits of precision in a compressed format. A BpsDecimal variable occupies 16 bytes.

Many thanks to IBM and IBM Fellow Mike Cowlishaw from the UK Laboratories, for making decNumber package widely available under the terms of ICU v1.8.1.

Constructor & Destructor Documentation

◆ BpsDecimal() [1/10]

BpsDecimal::BpsDecimal ( const BpsDecimal aOther)

The copy constructor.

Parameters
aOtherThe other number value to copy from.

◆ BpsDecimal() [2/10]

BpsDecimal::BpsDecimal ( qint32  aValue)

Construct from a signed 32 bit integer value.

Parameters
aValueThe integer value to copy from.

◆ BpsDecimal() [3/10]

BpsDecimal::BpsDecimal ( quint32  aValue)

Construct from a unsigned 32 bit integer value.

Parameters
aValueThe integer value to copy from.

◆ BpsDecimal() [4/10]

BpsDecimal::BpsDecimal ( qlonglong  aValue)

Construct from a 64 bit signed integer value.

Parameters
aValueThe integer value to copy from.

◆ BpsDecimal() [5/10]

BpsDecimal::BpsDecimal ( qulonglong  aValue)

Construct from a 64 bit unsigned integer value.

Parameters
aValueThe integer value to copy from.

◆ BpsDecimal() [6/10]

BpsDecimal::BpsDecimal ( double  aValue)

Construct from a double value.

Parameters
aValueThe double value to copy from.

◆ BpsDecimal() [7/10]

BpsDecimal::BpsDecimal ( const QString aString)

Construct from a decimal string representation.

The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe string to interpret as decimal number.

◆ BpsDecimal() [8/10]

BpsDecimal::BpsDecimal ( const QByteArray aString)

Construct from a decimal string representation.

The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe byte array to interpret as decimal number. The text is expected as 0-terminated string in constData().

◆ BpsDecimal() [9/10]

BpsDecimal::BpsDecimal ( const char *  aString)

Construct from a decimal string representation.

The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe 0-terminated string.

◆ BpsDecimal() [10/10]

BpsDecimal::BpsDecimal ( const QVariant aVariant)

Construct from a QVariant.

If the variant type is any numeric or string, the respective conversions are used. If the variant is invalid, null or not any numeric or string, the targets value is set to 0.

Parameters
aVariantThe source variant.

Member Function Documentation

◆ abs()

BpsDecimal BpsDecimal::abs ( ) const
Returns
Absolute value.

◆ ceil()

BpsDecimal BpsDecimal::ceil ( ) const

If the value is not integer, round up to next integer (towards +Infinity).

Returns
Integer value.

◆ div()

BpsDecimal BpsDecimal::div ( const BpsDecimal aOther) const

Divides this value by the other value and returns the integer part of the result.

Parameters
aOtherThe other value to divide by.
Returns
Integer result of the division.

◆ down()

BpsDecimal BpsDecimal::down ( ) const

If the value is not integer, round down to next integer (towards 0).

Returns
Integer value.

◆ exp()

BpsDecimal BpsDecimal::exp ( ) const

Calculate e to the power of this value and return the result.

Returns
Result e ** this.

◆ floor()

BpsDecimal BpsDecimal::floor ( ) const

If the value is not integer, round down to next integer (towards -Infinity).

Returns
Integer value.

◆ fromString() [1/3]

static BpsDecimal BpsDecimal::fromString ( const char *  aString,
bool *  aOk = 0 
)
static

Convert a string to a decimal value.

Parameters
aStringThe string to convert.
aOkIf not 0, *aOk is set true when conversion succeeded and false when conversion failed.
Returns
Returns the converted value, or 0 if conversion fails.

◆ fromString() [2/3]

static BpsDecimal BpsDecimal::fromString ( const QByteArray aString,
bool *  aOk = 0 
)
static

Convert a string to a decimal value.

Parameters
aStringThe string to convert.
aOkIf not 0, *aOk is set true when conversion succeeded and false when conversion failed.
Returns
Returns the converted value, or 0 if conversion fails.

◆ fromString() [3/3]

static BpsDecimal BpsDecimal::fromString ( const QString aString,
bool *  aOk = 0 
)
static

Convert a string to a decimal value.

Parameters
aStringThe string to convert.
aOkIf not 0, *aOk is set true when conversion succeeded and false when conversion failed.
Returns
Returns the converted value, or 0 if conversion fails.

◆ isFinite()

bool BpsDecimal::isFinite ( ) const

Check if value is neither infinite nor a NaN.

Returns
True if value is finite.

◆ isInfinite()

bool BpsDecimal::isInfinite ( ) const

Check if value is infinite.

Returns
True if value is infinite.

◆ isInteger()

bool BpsDecimal::isInteger ( ) const

Check if value is finite and has exponent=0.

Returns
True if value is integer.

◆ isNaN()

bool BpsDecimal::isNaN ( ) const

Check if value is not a number.

Returns
True if value is NaN.

◆ isNegative()

bool BpsDecimal::isNegative ( ) const

Check if value is negative.

Returns
True if value is negative.

◆ ln()

BpsDecimal BpsDecimal::ln ( ) const

Calculate the natural logarithm (to base e) of this value and return the result.

Returns
Natural logarithm of this value.

◆ log10()

BpsDecimal BpsDecimal::log10 ( ) const

Calculate the logarithm to base ten of this value and return the result.

Returns
Logarithm to base 10 of this value.

◆ max()

BpsDecimal BpsDecimal::max ( const BpsDecimal aOther) const

Compare this value with the other and return the larger (nearer towards +Infinity).

Parameters
aOtherThe other value to compare.
Returns
Larger of the two values.

◆ metaType()

static int BpsDecimal::metaType ( )
static
Returns
Get the Qt META type registered for BpsDecimal.

◆ min()

BpsDecimal BpsDecimal::min ( const BpsDecimal aOther) const

Compare this value with the other and return the smaller (nearer towards -Infinity).

Parameters
aOtherThe other value to compare.
Returns
Smaller of the two values.

◆ operator QVariant()

BpsDecimal::operator QVariant ( ) const

Automatic conversion to QVariant.

Returns
QVariant with the BpsDecimal value.

◆ operator!=()

bool BpsDecimal::operator!= ( const BpsDecimal aOther) const

Compare with other value for un-equality.

Parameters
aOtherThe other value to compare to.
Returns
True if not equal, false if equal.

◆ operator%()

BpsDecimal BpsDecimal::operator% ( const BpsDecimal aOther) const

Integer divide by other value and return remainder as result.

Parameters
aOtherThe other value to divide by.
Returns
The result value.

◆ operator%=()

BpsDecimal& BpsDecimal::operator%= ( const BpsDecimal aOther)

Integer divide by other value and set remainder as value.

Parameters
aOtherThe other value to divide by.
Returns
Reference to the value after operation.

◆ operator*()

BpsDecimal BpsDecimal::operator* ( const BpsDecimal aOther) const

Multiply with other value and return result.

Parameters
aOtherThe other value to multiply.
Returns
The result value.

◆ operator*=()

BpsDecimal& BpsDecimal::operator*= ( const BpsDecimal aOther)

Multiply with other value.

Parameters
aOtherThe other value.
Returns
Reference to the value after multiplication.

◆ operator+()

BpsDecimal BpsDecimal::operator+ ( const BpsDecimal aOther) const

Add two values and return result.

Parameters
aOtherThe other value to add.
Returns
The result value.

◆ operator++() [1/2]

BpsDecimal& BpsDecimal::operator++ ( )

Prefix increment the value by one.

Returns
Reference to the value after incrementing.

◆ operator++() [2/2]

BpsDecimal BpsDecimal::operator++ ( int  )

Postfix increment the value by one.

Returns
The value before incrementing.

◆ operator+=()

BpsDecimal& BpsDecimal::operator+= ( const BpsDecimal aOther)

Add other value.

Parameters
aOtherThe other value to add.
Returns
Reference to the value after addition.

◆ operator-()

BpsDecimal BpsDecimal::operator- ( const BpsDecimal aOther) const

Subtract second value and return result.

Parameters
aOtherThe other value to subtract.
Returns
The result value.

◆ operator--() [1/2]

BpsDecimal& BpsDecimal::operator-- ( )

Prefix decrement the value by one.

Returns
Reference to the value after incrementing.

◆ operator--() [2/2]

BpsDecimal BpsDecimal::operator-- ( int  )

Postfix decrement the value by one.

Returns
The value before decrementing.

◆ operator-=()

BpsDecimal& BpsDecimal::operator-= ( const BpsDecimal aOther)

Subtract second value.

Parameters
aOtherThe other value to subtract.
Returns
Reference to the value after subtraction.

◆ operator/()

BpsDecimal BpsDecimal::operator/ ( const BpsDecimal aOther) const

Divide by other value and return result.

Parameters
aOtherThe other value to divide by.
Returns
The result value.

◆ operator/=()

BpsDecimal& BpsDecimal::operator/= ( const BpsDecimal aOther)

Divide by other value.

Parameters
aOtherThe other value to divide by.
Returns
Reference to the value after division.

◆ operator<()

bool BpsDecimal::operator< ( const BpsDecimal aOther) const

Compare if less than other value.

Parameters
aOtherThe other value to compare to.
Returns
True if less, false if greater or equal other value.

◆ operator<=()

bool BpsDecimal::operator<= ( const BpsDecimal aOther) const

Compare if less than or equal to other value.

Parameters
aOtherThe other value to compare to.
Returns
True if less or equal, false if greater than other value.

◆ operator=() [1/10]

BpsDecimal& BpsDecimal::operator= ( const BpsDecimal aOther)

Assign value from an other decimal.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator=() [2/10]

BpsDecimal& BpsDecimal::operator= ( const char *  aString)

Assign value from a string.

Construct from a decimal string representation. The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe 0-terminated string.
Returns
Reference to the target value.

◆ operator=() [3/10]

BpsDecimal& BpsDecimal::operator= ( const QByteArray aString)

Assign value from a string.

Construct from a decimal string representation. The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe byte array to interpret as decimal number. The text is expected as 0-terminated string in constData().
Returns
Reference to the target value.

◆ operator=() [4/10]

BpsDecimal& BpsDecimal::operator= ( const QString aString)

Assign value from a string.

Construct from a decimal string representation. The string must follow the syntax: [+|-]integer-digits[.fraction-digits][e|E[+|-]exponent-digits]

Parameters
aStringThe string to interpret as decimal number.
Returns
Reference to the target value.

◆ operator=() [5/10]

BpsDecimal& BpsDecimal::operator= ( const QVariant aVariant)

Assign value from a QVariant.

If the variant type is any numeric or string, the respective conversions are used. If the variant is invalid, null or not any numeric or string, the targets value is set to 0.

Parameters
aVariantThe source variant.
Returns
Reference to the target value.

◆ operator=() [6/10]

BpsDecimal& BpsDecimal::operator= ( double  aOther)

Assign value from a double.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator=() [7/10]

BpsDecimal& BpsDecimal::operator= ( qint32  aOther)

Assign value from a 32 bit signed integer.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator=() [8/10]

BpsDecimal& BpsDecimal::operator= ( qlonglong  aOther)

Assign value from a 64 bit signed integer.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator=() [9/10]

BpsDecimal& BpsDecimal::operator= ( quint32  aOther)

Assign value from a 32 bit unsigned integer.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator=() [10/10]

BpsDecimal& BpsDecimal::operator= ( qulonglong  aOther)

Assign value from a 64 bit unsigned integer.

Parameters
aOtherThe other value to copy.
Returns
Reference to the target value.

◆ operator==()

bool BpsDecimal::operator== ( const BpsDecimal aOther) const

Compare with other value for equality.

Parameters
aOtherThe other value to compare to.
Returns
True if equal, false if not equal.

◆ operator>()

bool BpsDecimal::operator> ( const BpsDecimal aOther) const

Compare if greater than other value.

Parameters
aOtherThe other value to compare to.
Returns
True if greater, false if less or equal other value.

◆ operator>=()

bool BpsDecimal::operator>= ( const BpsDecimal aOther) const

Compare if greater than or equal to other value.

Parameters
aOtherThe other value to compare to.
Returns
True if greater or equal, false if less than other value.

◆ Pi()

static BpsDecimal BpsDecimal::Pi ( )
static
Returns
Ratio of the circumference of a circle to the diameter.

◆ power()

BpsDecimal BpsDecimal::power ( const BpsDecimal aOther) const

Raises this value to the power of the other value and returns the result.

Parameters
aOtherThe other value.
Returns
Result of this ** aOther.

◆ rounded()

BpsDecimal BpsDecimal::rounded ( int  aDecPlaces) const

Round to an number of decimal places.

Parameters
aDecPlacesNumber of decimal places to round to.
Returns
Rounded value.

◆ sqrt()

BpsDecimal BpsDecimal::sqrt ( ) const

Calculate the square root of this value and return the result.

Returns
Square root of this value.

◆ toDouble()

double BpsDecimal::toDouble ( ) const

Get the value as double.

Returns
The value as double.

◆ toInt()

qint32 BpsDecimal::toInt ( ) const

Get the value as signed 32 bit integer.

The value is rounded to an integer if necessary. If x is infinite, is a NaN, or after rounding is outside the range of the result, then StatusInvalidOperation is set. The StatusInexact flag is not set by this function, even if rounding occurred.

Returns
The value as qint32.

◆ toLongLong()

qlonglong BpsDecimal::toLongLong ( ) const

Get the value as 64 bit signed integer.

The value is rounded to an integral value.

Returns
The value as qlonglong.

◆ toString() [1/2]

QString BpsDecimal::toString ( ) const

Converts a decimal value to a string.

Finite numbers are converted to a string of format [-]9.9 if the final string is 20 characters or less, and to exponential notation otherwise.

Note that strings which are not regular numbers (one of "Infinity", "-Infinity", "NaN") are possible.

Returns
String representation of the value.

◆ toString() [2/2]

QString BpsDecimal::toString ( int  aDecPlaces,
int  aMaxSize = 36 
) const

Converts a decimal value to a string of format [-]9.9.

The printed value is rounded to the absolute number of decimal places.

  • If the value is NaN, the string "NaN" is returned.
  • If the value is infinite or the string does not fit into the given maximum size, a maximum size string of hashes is returned as "#####" for positive values or "-####" for negative values.
  • if the value is finite and aDecPlaces is greater than 0, all fractional digits for the given decimal places are included.
  • If the value is finite, aDecPlaces is less than 0, and all fractional digits are zero, the fractional part is removed and the value is represented as integer.
Parameters
aDecPlacesNumber of decimal places.
aMaxSizeMaximum string size.
Returns
String representation of the value.

◆ toUInt()

quint32 BpsDecimal::toUInt ( ) const

Get the value as unsigned 32 bit integer.

The value is rounded to an integer if necessary. If x is infinite, is a NaN, or after rounding is outside the range of the result, then StatusInvalidOperation is set. The StatusInexact flag is not set by this function, even if rounding occurred.

Returns
The value as quint32.

◆ toULongLong()

qulonglong BpsDecimal::toULongLong ( ) const

Get the value as 64 bit unsigned integer.

The value is rounded to an integral value >= 0.

Returns
The value as qulonglong.

◆ toVariant()

QVariant BpsDecimal::toVariant ( ) const

Explicit conversion to QVariant.

Returns
QVariant with the BpsDecimal value.

◆ up()

BpsDecimal BpsDecimal::up ( ) const

If the value is not integer, round up to next integer (away from 0).

Returns
Integer value.

Friends And Related Function Documentation

◆ operator-()

BPSCORE_EXPORT BpsDecimal operator- ( const BpsDecimal aValue)
related

Unary prefix minus operator.

Parameters
aValueThe decimal to get the negative value of.
Returns
The negative value.

◆ operator<<() [1/4]

BPSCORE_EXPORT QDataStream & operator<< ( QDataStream aStream,
const BpsDecimal aDecimal 
)
related

Write the binary code of the decimal value to a data stream.

Parameters
aStreamThe stream to write to.
aDecimalThe BpsDecimal value.
Returns
Stream reference.

◆ operator<<() [2/4]

BPSCORE_EXPORT QDebug operator<< ( QDebug  aDebug,
const BpsDecimal aDecimal 
)
related

Write the string representation of a decimal value to a debug stream.

Parameters
aDebugThe stream to write to.
aDecimalThe BpsDecimal value.
Returns
Stream reference.

◆ operator<<() [3/4]

BPSCORE_EXPORT QTextStream & operator<< ( QTextStream aStream,
const BpsDecimal aDecimal 
)
related

Write the string representation of the decimal value to a text stream.

Parameters
aStreamThe stream to write to.
aDecimalThe BpsDecimal value.
Returns
Stream reference.

◆ operator<<() [4/4]

BPSCORE_EXPORT std::ostream & operator<< ( std::ostream &  aStream,
const BpsDecimal aDecimal 
)
related

Write the string representation of the decimal value to a std::ostream.

Parameters
aStreamThe stream to write to.
aDecimalThe BpsDecimal value.
Returns
Stream reference.

◆ operator>>()

BPSCORE_EXPORT QDataStream & operator>> ( QDataStream aStream,
BpsDecimal aDecimal 
)
related

Read the binary code of the decimal value from a data stream.

Parameters
aStreamThe stream to read from.
aDecimalThe BpsDecimal value.
Returns
Stream reference.

◆ qHash()

BPSCORE_EXPORT uint qHash ( const BpsDecimal aValue,
uint  aSeed 
)
related

Returns a hash value, as required by QHash or QSet.

Parameters
aValueThe value to creat a hash for.
aSeedUnique seed to lower atackability.
Returns
The calculated hash.

The documentation for this class was generated from the following file: