SQL numeric/decimal 提高多精度

SQL numeric/decimal to boost multiprecision

我正在寻找一些 C++ 中的(非字符串)类型,我们可以用它来存储 SQL numeric(18, 4)(或 decimal(18, 4))值。我浏览了 boost 的文档 cpp_dec_float,但对于如何使用它仍然很困惑:

When the doc says "decimal digits" (e.g. in "The typedefs cpp_dec_float_50 and cpp_dec_float_100 provide arithmetic types at 50 and 100 decimal digits precision respectively"), is it referring to the number of digits to the right of the decimal point or all the significant digits?

所有有效数字。

std::numeric_limits<number<cpp_dec_float<50>>>::digits10 is 50 but std::numeric_limits<number<cpp_dec_float<4>>>::digits10 is 9. Why is that?

这是一个实现细节。基本上,图书馆提供了向您提供承诺的 4 位数字所需的最低限度

If the Digits10 template parameter is the number of all significant digits, does it mean there is no way to specify a fixed precision and a scale (as in SQL numeric(18, 4)) for boost multiprecision types?

确实如此。简而言之,多精度库不提供任何定点类型(尽管您显然可以使用 cpp_int