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, representing exact decimal values with defined precision.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class is available in various versions, with the latest release candidate being 2.37.0-rc and it supports being constructed from and converted to strings, doubles, and integral types.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDecimal\u003c/code\u003e values are copyable, assignable, movable, comparable, and can be streamed, with methods like \u003ccode\u003eToString()\u003c/code\u003e offering string representations of the decimal value.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMakeDecimal()\u003c/code\u003e factory function, along with \u003ccode\u003eToString()\u003c/code\u003e, \u003ccode\u003eToDouble()\u003c/code\u003e, and \u003ccode\u003eToInteger()\u003c/code\u003e functions, are key methods for creating and converting \u003ccode\u003eDecimal\u003c/code\u003e objects.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDecimal\u003c/code\u003e includes constructors such as \u003ccode\u003eDecimal(Decimal &&)\u003c/code\u003e and \u003ccode\u003eDecimal(Decimal const &)\u003c/code\u003e to support copy and move operations, along with an empty constructor to construct a zero value, as well as operators.\u003c/p\u003e\n"]]],[],null,[]]