|
virtual UString | description () const =0 |
| Get a textual description of the values of that type.
|
|
virtual bool | fromString (const UString &str, UChar separator=COMMA, UChar decimal_dot=FULL_STOP)=0 |
| Parse a string and interpret it as a number.
|
|
virtual bool | inRange (int64_t min, int64_t max) const =0 |
| Check if the value of the number is within a range of integer value.
|
|
virtual double | toDouble () const =0 |
| Conversion to double value.
|
|
virtual int64_t | toInt64 () const =0 |
| Conversion to a 64-bit signed integer value.
|
|
virtual UString | toString (size_t min_width=0, bool right_justified=true, UChar separator=COMMA, bool force_sign=false, size_t decimals=NPOS, bool force_decimals=false, UChar decimal_dot=FULL_STOP, UChar pad=SPACE) const =0 |
| Convert the number to a string object.
|
|
Abstract base class for different representations of "numbers".
All arithmetic and comparison operators shall be defined by concrete subclasses between number instances and between a number instance and an integer value, both directions.
- See also
- FixedPoint
-
Fraction
-
Double
virtual UString ts::AbstractNumber::toString |
( |
size_t |
min_width = 0 , |
|
|
bool |
right_justified = true , |
|
|
UChar |
separator = COMMA , |
|
|
bool |
force_sign = false , |
|
|
size_t |
decimals = NPOS , |
|
|
bool |
force_decimals = false , |
|
|
UChar |
decimal_dot = FULL_STOP , |
|
|
UChar |
pad = SPACE |
|
) |
| const |
|
pure virtual |
Convert the number to a string object.
- Parameters
-
[in] | min_width | Minimum width of the returned string. Padded with pad characters if larger than the number of characters in the formatted number. |
[in] | right_justified | If true (the default), return a right-justified string. When false, return a left-justified string. Ignored if min_width is lower than the number of characters in the formatted number. |
[in] | separator | Separator character for groups of thousands, a comma by default. CHAR_NULL means no separator. |
[in] | force_sign | If true, force a '+' sign for positive values. |
[in] | decimals | Precision to use after the decimal point. NPOS means default. |
[in] | force_decimals | If true, with positive precision, force a decimal dot and the number of decimal digits of the precision. By default, skip non significant decimal digits. |
[in] | decimal_dot | The decimal separator, a dot by default. |
[in] | pad | The padding character to adjust the width. |
- Returns
- The formatted string.
Implemented in ts::FixedPoint< INT_T, PREC, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, ts::Fraction< INT_T, type >, ts::Fraction< uint32_t >, and ts::Integer< INT_T, type >.
Parse a string and interpret it as a number.
The content of this object is updated from the parsed string.
- Parameters
-
[in] | str | A string to parse, representing this object. |
[in] | separator | Separator character for groups of thousands, a comma by default. |
[in] | decimal_dot | The decimal separator, a dot by default. |
- Returns
- True if the str is valid, false otherwise. In case of parsing error, the content of this object is undefined.
Implemented in ts::FixedPoint< INT_T, PREC, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, ts::Fraction< INT_T, type >, ts::Fraction< uint32_t >, and ts::Integer< INT_T, type >.