Represents a percentage value for use in mathematical calculations or user interfaces. More...
#include <Percentage.h>
Public Member Functions | |
Percentage (const double rate=0.0, const quint8 precision=Percentage::defaultPrecision) | |
Full initialisation constructor. | |
operator double () const noexcept | |
Conversion operator to the decimal representation of the percentage. | |
std::strong_ordering | operator<=> (const double rate) const noexcept |
std::strong_ordering | operator<=> (const Percentage &other) const noexcept |
bool | operator== (const double rate) const noexcept |
bool | operator== (const Percentage &) const noexcept=default |
quint8 | precision () const noexcept |
An accessor to the number of digits to use in any operation involving the rate. | |
double | rate () const noexcept |
An accessor to the percentage rate. | |
Static Public Attributes | |
static constexpr const quint8 | defaultPrecision {6u} |
Friends | |
DRN_FOUNDATION_EXPORT std::ostream & | operator<< (std::ostream &out, const Percentage &p) |
Full object stream insertion operator. | |
DRN_FOUNDATION_EXPORT::QString | presentationText (const Percentage &p) |
Generates a text representation for a percentage value. | |
Represents a percentage value for use in mathematical calculations or user interfaces.
It is designed to simplify the representation and manipulation of fractional values expressed as percentages. It provides utility methods for converting between percentages and decimal values, as well as for formatting percentage values for display in graphical user interfaces or other textual outputs.
|
explicit |
Full initialisation constructor.
Error | When the rate is too large to truncate. |
rate | The percentage rate value. Any digits after the precision is truncated. |
precision | The number of digits after the decimal point. |
|
explicitnoexcept |
Conversion operator to the decimal representation of the percentage.
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscardnoexcept |
|
nodiscarddefaultnoexcept |
|
nodiscardnoexcept |
An accessor to the number of digits to use in any operation involving the rate.
|
nodiscardnoexcept |
An accessor to the percentage rate.
|
friend |
Full object stream insertion operator.
out | The stream to place the data into. |
p | The data to place into the stream. |
|
friend |
Generates a text representation for a percentage value.
This function creates a formatted string displaying the percentage value based on the rate and precision defined in the provided percentage object. It is useful for displaying percentage values in a user-readable format, such as in GUIs, logs, or reports.
p | An object representing the percentage, containing the rate and precision. |
|
staticconstexpr |
N.B. The number of decimal places is chosen because it seems to be good enough for the number of digits most percentage rates are advertised in.