|
Lightweight 0.20260921.0
|
A fixed-point decimal whose precision and scale are known only at run time. More...
#include <SqlDynamicNumeric.hpp>
Public Member Functions | |
| constexpr bool | operator== (SqlDynamicNumeric const &other) const noexcept |
| constexpr bool | operator!= (SqlDynamicNumeric const &other) const noexcept |
| Inequality, derived from operator==. | |
| constexpr double | ToDouble () const noexcept |
| std::string | ToString () const |
| Renders the exact decimal representation, including the trailing zeros implied by scale. | |
Static Public Member Functions | |
| static constexpr std::optional< SqlDynamicNumeric > | FromString (std::string_view text, std::uint8_t precision, std::uint8_t scale) noexcept |
Public Attributes | |
| std::int64_t | unscaledValue = 0 |
The value, scaled by 10^scale. 12.34 at scale 2 is stored as 1234. | |
| std::uint8_t | precision = 0 |
| Total number of decimal digits the source column holds. | |
| std::uint8_t | scale = 0 |
| Number of digits after the decimal point. | |
A fixed-point decimal whose precision and scale are known only at run time.
This is the dynamic counterpart to SqlNumeric. Where SqlNumeric<Precision, Scale> fixes both at compile time, a value fetched into a SqlVariant learns its precision and scale from the result-set metadata, so they have to travel with the value.
The number is held exactly, as the unscaled integer value * 10^scale, and never passes through a binary floating-point type. That is the point of the type: DECIMAL(19, 4) — what MS SQL Server's money maps to — carries more significant digits than a double can represent, so reading such a column as double loses cents on large amounts.
Definition at line 239 of file SqlDynamicNumeric.hpp.
|
inlineconstexprnoexcept |
Compares two values by mathematical magnitude, so the same number at different scales compares equal (1.50 at scale 2 equals 1.5 at scale 1).
Definition at line 252 of file SqlDynamicNumeric.hpp.
References scale, and unscaledValue.
|
inlineconstexprnoexcept |
Inequality, derived from operator==.
Definition at line 271 of file SqlDynamicNumeric.hpp.
|
inlineconstexprnoexcept |
Converts to a floating-point approximation.
double carries; read unscaledValue together with scale when exactness matters. Definition at line 280 of file SqlDynamicNumeric.hpp.
References scale, and unscaledValue.
|
inline |
Renders the exact decimal representation, including the trailing zeros implied by scale.
Definition at line 294 of file SqlDynamicNumeric.hpp.
References scale, and unscaledValue.
Referenced by Lightweight::SqlDataBinder< SqlDynamicNumeric >::Inspect().
|
inlinestaticconstexprnoexcept |
Parses an exact decimal literal, scaling it to scale.
| text | The decimal literal, as an ODBC driver renders a DECIMAL/NUMERIC column. |
| precision | Total digit count to record on the result. |
| scale | Fractional digit count to scale the value to. |
| std::nullopt | text is not a plain decimal literal, or does not fit the scale. |
Definition at line 317 of file SqlDynamicNumeric.hpp.
References precision, scale, and unscaledValue.
Referenced by Lightweight::SqlDataBinder< SqlDynamicNumeric >::FromColumnLiteral().
| std::int64_t Lightweight::SqlDynamicNumeric::unscaledValue = 0 |
The value, scaled by 10^scale. 12.34 at scale 2 is stored as 1234.
Definition at line 242 of file SqlDynamicNumeric.hpp.
Referenced by FromString(), operator==(), ToDouble(), and ToString().
| std::uint8_t Lightweight::SqlDynamicNumeric::precision = 0 |
Total number of decimal digits the source column holds.
Definition at line 245 of file SqlDynamicNumeric.hpp.
Referenced by FromString().
| std::uint8_t Lightweight::SqlDynamicNumeric::scale = 0 |
Number of digits after the decimal point.
Definition at line 248 of file SqlDynamicNumeric.hpp.
Referenced by FromString(), operator==(), ToDouble(), and ToString().