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 specified precision.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDecimal\u003c/code\u003e class can be constructed from and converted to various types including \u003ccode\u003estd::string\u003c/code\u003e, \u003ccode\u003edouble\u003c/code\u003e, and integral types using factory functions like \u003ccode\u003eMakeDecimal()\u003c/code\u003e, and functions \u003ccode\u003eToString()\u003c/code\u003e, \u003ccode\u003eToDouble()\u003c/code\u003e, and \u003ccode\u003eToInteger()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDecimal\u003c/code\u003e objects support standard operations such as copying, assigning, moving, and comparing for equality.\u003c/p\u003e\n"],["\u003cp\u003eThe document provides detailed information on the versions, up to version \u003ccode\u003e2.37.0-rc\u003c/code\u003e, of the Spanner C++ library, providing a link for each version to the documentation for class Decimal.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToString()\u003c/code\u003e function can convert a \u003ccode\u003eDecimal\u003c/code\u003e object to a decimal-string representation, with specific formats for different value ranges and the \u003ccode\u003eNaN\u003c/code\u003e case for kPostgreSQL mode.\u003c/p\u003e\n"]]],[],null,[]]