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\u003eThis document outlines the \u003ccode\u003eDecimal\u003c/code\u003e class within the Google Cloud Spanner C++ library, which represents the Spanner NUMERIC type as an exact decimal value with defined precision.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class is a regular value type supporting copy, assignment, and move operations, and offers construction from strings, doubles, or integers via the \u003ccode\u003eMakeDecimal()\u003c/code\u003e factory functions.\u003c/p\u003e\n"],["\u003cp\u003eIt can be converted to a string via \u003ccode\u003eToString()\u003c/code\u003e and to integer or double via the \u003ccode\u003eToInteger()\u003c/code\u003e and \u003ccode\u003eToDouble()\u003c/code\u003e free functions, and offers support for operations including comparison and streaming.\u003c/p\u003e\n"],["\u003cp\u003eThe available versions of the documentation range from version 2.11.0 to 2.37.0-rc, including detailed specifications for each version for the \u003ccode\u003eDecimal\u003c/code\u003e class and its functionalities.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToString()\u003c/code\u003e function provides a decimal-string representation of the \u003ccode\u003eDecimal\u003c/code\u003e, without an exponent field, in formats for zero values, values between 0 and 1, values greater than or equal to 1, and "NaN" for kPostgreSQL mode.\u003c/p\u003e\n"]]],[],null,[]]