Represents an unsigned fixed-point numeric value with a configurable number of decimal points. Not general purpose, intended usage is for only exchange connectivity.
More...
Represents an unsigned fixed-point numeric value with a configurable number of decimal points. Not general purpose, intended usage is for only exchange connectivity.
- Decimal points represent the scale factor. For example: in
10.32, decimal points = 2.
- If decimal points is 4, a raw value of
10000 represents 1.0000.
- Some common decimal point examples used by exchanges:
- 4 (Nasdaq OMX)
- 6 (Euronext)
- 7 (Euronext)
- 8 (Xetra & Eurex)
- Raw value is stored as a 64-bit unsigned integer, matching typical exchange-native binary protocol fields (e.g. price).
- Arithmetic operations not supported. You can use get_raw_value and set_raw_value to modify the underlying value
- Warning
- You must not use a FixedPoint instance without setting decimal points.
- set_from_chars assumes a strictly valid unsigned decimal representation. Accepted format: digits with an optional single '.' delimiter (e.g. "123", "123.45"). The parser does not validate or skip whitespace, signs, separators, exponent notation, or multiple '.' characters. Any non-digit (other than a single '.') or multiple '.' occurrences yield undefined/implementation-specific results.
Usage
Example 1
FixedPoint fp;
fp.set_decimal_points(4);
fp.set_from_chars("1000.0023");
std::cout << fp.to_string();
std::cout << fp.get_raw_value();
Example 2
FixedPoint fp;
fp.set_decimal_points(4);
fp.set_raw_value(10001234);
std::cout << fp.to_string();
std::cout << fp.get_raw_value();