Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
Public Member Functions | Friends | List of all members
google::cloud::spanner::v1::Numeric Class Reference

A representation of the Spanner NUMERIC type: an exact numeric value with 29 decimal digits of integer precision (kIntPrec) and 9 decimal digits of fractional precision (kFracPrec). More...

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

Public Member Functions

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

Static Public Attributes

static constexpr std::size_t kIntPrec = 29
 Decimal integer and fractional precision of a Numeric value. More...
 
static constexpr std::size_t kFracPrec = 9
 Decimal integer and fractional precision of a Numeric value. More...
 

Friends

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

Detailed Description

A representation of the Spanner NUMERIC type: an exact numeric value with 29 decimal digits of integer precision (kIntPrec) and 9 decimal digits of fractional precision (kFracPrec).

So, the range of a Numeric is -99999999999999999999999999999.999999999 to 99999999999999999999999999999.999999999.

A Numeric can be constructed from, and converted to a std::string, a double, or any integral type. See the MakeNumeric() factory functions, the ToString() member function, and the ToDouble()/ToInteger() free functions.

Numeric values can be copied/assigned/moved, compared for equality, and streamed.

Example
assert(n.ToString() == "1234");
assert(spanner::ToInteger<int>(n).value() == 1234);
A representation of the Spanner NUMERIC type: an exact numeric value with 29 decimal digits of intege...
Definition: numeric.h:85
std::string const & ToString() const &
Conversion to a decimal-string representation of the Numeric in one of the following forms:
Definition: numeric.h:115
StatusOr< Numeric > MakeNumeric(std::string s)
Construction from a string, in decimal fixed- or floating-point formats.
Definition: numeric.cc:245

Definition at line 85 of file numeric.h.

Constructor & Destructor Documentation

◆ Numeric() [1/3]

google::cloud::spanner::v1::Numeric::Numeric ( )

A zero value.

Definition at line 243 of file numeric.cc.

◆ Numeric() [2/3]

google::cloud::spanner::v1::Numeric::Numeric ( Numeric &&  )
default

Regular value type, supporting copy, assign, move.

◆ Numeric() [3/3]

google::cloud::spanner::v1::Numeric::Numeric ( Numeric const &  )
default

Regular value type, supporting copy, assign, move.

Member Function Documentation

◆ operator=() [1/2]

Numeric& google::cloud::spanner::v1::Numeric::operator= ( Numeric &&  )
default

Regular value type, supporting copy, assign, move.

◆ operator=() [2/2]

Numeric& google::cloud::spanner::v1::Numeric::operator= ( Numeric const &  )
default

Regular value type, supporting copy, assign, move.

◆ ToString() [1/2]

std::string&& google::cloud::spanner::v1::Numeric::ToString ( ) &&
inline

Conversion to a decimal-string representation of the Numeric in one of the following forms:

  • 0 // value == 0
  • -?0.[0-9]{0,8}[1-9] // 0 < abs(value) < 1
  • -?[1-9][0-9]{0,28}(.[0-9]{0,8}[1-9])? // abs(value) >= 1

Note: The string never includes an exponent field.

Definition at line 116 of file numeric.h.

◆ ToString() [2/2]

std::string const& google::cloud::spanner::v1::Numeric::ToString ( ) const &
inline

Conversion to a decimal-string representation of the Numeric in one of the following forms:

  • 0 // value == 0
  • -?0.[0-9]{0,8}[1-9] // 0 < abs(value) < 1
  • -?[1-9][0-9]{0,28}(.[0-9]{0,8}[1-9])? // abs(value) >= 1

Note: The string never includes an exponent field.

Definition at line 115 of file numeric.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( Numeric const &  a,
Numeric const &  b 
)
friend

Relational operators.

Definition at line 124 of file numeric.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
Numeric const &  n 
)
friend

Outputs string representation of the Numeric to the provided stream.

Definition at line 130 of file numeric.h.

◆ operator==

bool operator== ( Numeric const &  a,
Numeric const &  b 
)
friend

Relational operators.

Definition at line 121 of file numeric.h.

Member Data Documentation

◆ kFracPrec

constexpr std::size_t google::cloud::spanner::v1::Numeric::kFracPrec = 9
staticconstexpr

Decimal integer and fractional precision of a Numeric value.

Definition at line 90 of file numeric.h.

◆ kIntPrec

constexpr std::size_t google::cloud::spanner::v1::Numeric::kIntPrec = 29
staticconstexpr

Decimal integer and fractional precision of a Numeric value.

Definition at line 89 of file numeric.h.