A representation of the Spanner NUMERIC type: an exact decimal value with a maximum integer precision (kIntPrecision) and rounding to a maximum fractional precision (kFracPrecision).
A Decimal can be constructed from, and converted to a std::string, a double, or any integral type. See the MakeDecimal() factory functions, the ToString() member function, and the ToDouble()/ToInteger() free functions.
Decimal values can be copied/assigned/moved, compared for equality, and streamed.
Example
auto d = spanner::MakeDecimal<spanner::DecimalMode::kGoogleSQL>(42).value();
assert(d.ToString() == "42");
assert(spanner::ToInteger<int>(d).value() == 42);
Constructors
Decimal(Decimal &&)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
Decimal &&
Decimal(Decimal const &)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
Decimal const &
Decimal()
A zero value.
Operators
operator=(Decimal &&)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
Decimal &&
Returns
Type
Description
Decimal &
operator=(Decimal const &)
Regular value type, supporting copy, assign, move.
Parameter
Name
Description
Decimal const &
Returns
Type
Description
Decimal &
Functions
ToString() const &
Conversion to a decimal-string representation of the Decimal in one of the following forms:
0 // value == 0
-?0.[0-9]*[1-9] // 0 < abs(value) < 1
-?[1-9][0-9](.[0-9][1-9])? // abs(value) >= 1
NaN // "not a number" for kPostgreSQL mode
Note: The string never includes an exponent field.
Returns
Type
Description
std::string const &
ToString() &&
Conversion to a decimal-string representation of the Decimal in one of the following forms:
0 // value == 0
-?0.[0-9]*[1-9] // 0 < abs(value) < 1
-?[1-9][0-9](.[0-9][1-9])? // abs(value) >= 1
NaN // "not a number" for kPostgreSQL mode
Note: The string never includes an exponent field.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-22 UTC."],[[["\u003cp\u003eThe content describes the \u003ccode\u003eDecimal\u003c/code\u003e class in the Google Cloud Spanner C++ library, representing an exact decimal value with specified precision.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDecimal\u003c/code\u003e objects can be constructed from and converted to \u003ccode\u003estd::string\u003c/code\u003e, \u003ccode\u003edouble\u003c/code\u003e, or integral types, and also utilize factory functions and specific functions like \u003ccode\u003eToString()\u003c/code\u003e, \u003ccode\u003eToDouble()\u003c/code\u003e, and \u003ccode\u003eToInteger()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class supports standard operations such as copying, assignment, moving, and equality comparison, along with the ability to be streamed.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToString()\u003c/code\u003e method provides a decimal-string representation of the \u003ccode\u003eDecimal\u003c/code\u003e value without an exponent field, adhering to specific formatting rules for zero, values less than one, and values greater than or equal to one, along with "NaN" for the kPostgreSQL mode.\u003c/p\u003e\n"],["\u003cp\u003eThere are multiple versions of the \u003ccode\u003eDecimal\u003c/code\u003e class being displayed, with \u003ccode\u003e2.37.0-rc\u003c/code\u003e being the latest version available.\u003c/p\u003e\n"]]],[],null,[]]