Class Decimal<> (2.33.0)

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.

Returns
Type Description
std::string &&