Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Friends | List of all members
google::cloud::spanner::Decimal< DecimalMode > Class Template Reference

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). More...

#include <google/cloud/spanner/numeric.h>

Public Member Functions

 Decimal ()
 A zero value. More...
 
Regular value type, supporting copy, assign, move.
 Decimal (Decimal &&) noexcept=default
 
Decimaloperator= (Decimal &&) noexcept=default
 
 Decimal (Decimal const &)=default
 
Decimaloperator= (Decimal const &)=default
 
std::string const & ToString () const &
 Conversion to a decimal-string representation of the Decimal in one of the following forms: More...
 
std::string && ToString () &&
 Conversion to a decimal-string representation of the Decimal in one of the following forms: More...
 

Static Public Attributes

static bool const kHasNaN
 Whether DecimalMode supports NaN values. More...
 
Integer and fractional precision of a <tt>Decimal</tt> value of the mode.
static std::size_t const kIntPrecision
 
static std::size_t const kFracPrecision
 
Backwards-compatibility constants.
Deprecated:
Only apply to kGoogleSQL mode, and are no longer used in the implementation.
static constexpr std::size_t kIntPrec = 29
 
static constexpr std::size_t kFracPrec = 9
 

Friends

std::ostream & operator<< (std::ostream &os, Decimal const &d)
 Outputs string representation of the Decimal to the provided stream. More...
 
Relational operators
bool operator== (Decimal const &a, Decimal const &b)
 
bool operator!= (Decimal const &a, Decimal const &b)
 

Detailed Description

template<DecimalMode>
class google::cloud::spanner::Decimal< DecimalMode >

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);

Constructor & Destructor Documentation

◆ Decimal() [1/3]

template<DecimalMode >
google::cloud::spanner::Decimal< DecimalMode >::Decimal ( )
inline

A zero value.

◆ Decimal() [2/3]

template<DecimalMode >
google::cloud::spanner::Decimal< DecimalMode >::Decimal ( Decimal< DecimalMode > &&  )
defaultnoexcept

◆ Decimal() [3/3]

template<DecimalMode >
google::cloud::spanner::Decimal< DecimalMode >::Decimal ( Decimal< DecimalMode > const &  )
default

Member Function Documentation

◆ operator=() [1/2]

template<DecimalMode >
Decimal & google::cloud::spanner::Decimal< DecimalMode >::operator= ( Decimal< DecimalMode > &&  )
defaultnoexcept

◆ operator=() [2/2]

template<DecimalMode >
Decimal & google::cloud::spanner::Decimal< DecimalMode >::operator= ( Decimal< DecimalMode > const &  )
default

◆ ToString() [1/2]

template<DecimalMode >
std::string && google::cloud::spanner::Decimal< DecimalMode >::ToString ( ) &&
inline

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.

◆ ToString() [2/2]

template<DecimalMode >
std::string const & google::cloud::spanner::Decimal< DecimalMode >::ToString ( ) const &
inline

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.

Friends And Related Function Documentation

◆ operator!=

template<DecimalMode >
bool operator!= ( Decimal< DecimalMode > const &  a,
Decimal< DecimalMode > const &  b 
)
friend

◆ operator<<

template<DecimalMode >
std::ostream & operator<< ( std::ostream &  os,
Decimal< DecimalMode > const &  d 
)
friend

Outputs string representation of the Decimal to the provided stream.

◆ operator==

template<DecimalMode >
bool operator== ( Decimal< DecimalMode > const &  a,
Decimal< DecimalMode > const &  b 
)
friend

Member Data Documentation

◆ kFracPrec

template<DecimalMode Mode>
constexpr std::size_t google::cloud::spanner::Decimal< Mode >::kFracPrec = 9
staticconstexpr

◆ kFracPrecision

template<DecimalMode >
std::size_t const google::cloud::spanner::Decimal< DecimalMode >::kFracPrecision
static

◆ kHasNaN

template<DecimalMode >
bool const google::cloud::spanner::Decimal< DecimalMode >::kHasNaN
static

Whether DecimalMode supports NaN values.

◆ kIntPrec

template<DecimalMode Mode>
constexpr std::size_t google::cloud::spanner::Decimal< Mode >::kIntPrec = 29
staticconstexpr

◆ kIntPrecision

template<DecimalMode >
std::size_t const google::cloud::spanner::Decimal< DecimalMode >::kIntPrecision
static