Google Cloud Spanner v1 API - Struct PgNumeric (5.0.0-beta03)

public readonly struct PgNumeric : IEquatable<PgNumeric>, IComparable<PgNumeric>, IComparable

Reference documentation and code samples for the Google Cloud Spanner v1 API struct PgNumeric.

Representation of PostgreSQL numeric type which has max precision of 147455 and a max scale of 16383.

Namespace

Google.Cloud.Spanner.V1

Assembly

Google.Cloud.Spanner.V1.dll

Properties

MaxValue

public static PgNumeric MaxValue { get; }

The maximum valid value for PgNumeric, equal to BigInteger.Pow(10, 147455) - 1

Property Value
TypeDescription
PgNumeric

MinValue

public static PgNumeric MinValue { get; }

The minimum valid value for PgNumeric, equal to -(BigInteger.Pow(10, 147455) - 1)

Property Value
TypeDescription
PgNumeric

NaN

public static PgNumeric NaN { get; }

NaN (Not a number) represented as a PgNumeric.

Property Value
TypeDescription
PgNumeric

Zero

public static PgNumeric Zero { get; }

Zero represented as a PgNumeric. This is the default value for the type.

Property Value
TypeDescription
PgNumeric

Methods

CompareTo(PgNumeric)

public int CompareTo(PgNumeric other)
Parameter
NameDescription
otherPgNumeric
Returns
TypeDescription
int

FromDecimal(decimal)

public static PgNumeric FromDecimal(decimal value)

Converts a decimal value to PgNumeric,

Parameter
NameDescription
valuedecimal

The value to convert

Returns
TypeDescription
PgNumeric

The converted value.

GetHashCode()

public override int GetHashCode()
Returns
TypeDescription
int
Overrides

Parse(string)

public static PgNumeric Parse(string text)

Parses a textual representation as a PgNumeric.

Parameter
NameDescription
textstring

The text to parse. Must not be null.

Returns
TypeDescription
PgNumeric

The parsed value.

Remarks

text must be a representation of a decimal value which can be represented by PgNumeric, using "." as a decimal place where one is specified, and a leading "-" for negative values. Leading zeroes and insignificant trailing digits are permitted.

Exceptions
TypeDescription
FormatException

The value could not be parsed as a PgNumeric.

ToDecimal(LossOfPrecisionHandling)

public decimal ToDecimal(LossOfPrecisionHandling lossOfPrecisionHandling)

Converts this value to PgNumeric,

Parameter
NameDescription
lossOfPrecisionHandlingLossOfPrecisionHandling

How to handle values with signficant digits that would be lost by the conversion.

Returns
TypeDescription
decimal

The converted value.

Remarks

This conversion may silently lose precision, depending on lossOfPrecisionHandling, but will always throw OverflowException if value is out of the range of decimal.

Exceptions
TypeDescription
OverflowException

This value is outside the range of decimal.

ToString()

public override string ToString()

Returns a canonical string representation of this value. This always uses "." as a decimal point. If the value is between -1 and 1 exclusive, a "0" character is included before the decimal point.

Returns
TypeDescription
string

A canonical string representation of this value.

Overrides

TryParse(string, out PgNumeric)

public static bool TryParse(string text, out PgNumeric value)

Attempts to parse a textual representation of a PgNumeric value.

Parameters
NameDescription
textstring

The text to parse. Must not be null.

valuePgNumeric

The parsed value, or 0 on failure.

Returns
TypeDescription
bool

true if text was parsed successfully; false otherwise.

Remarks

See Parse(string) for format details. This method will return true if and only if Parse(string) would return without an exception.

Operators

operator ==(PgNumeric, PgNumeric)

public static bool operator ==(PgNumeric lhs, PgNumeric rhs)

Compares two values for equality.

Parameters
NameDescription
lhsPgNumeric

The first value to compare.

rhsPgNumeric

The second value to compare.

Returns
TypeDescription
bool

true if the two arguments are equal; false otherwise.

explicit operator decimal(PgNumeric)

public static explicit operator decimal(PgNumeric value)

Explicit conversion from PgNumeric to decimal.

Parameter
NameDescription
valuePgNumeric

The numeric value to convert.

Returns
TypeDescription
decimal

The result of the conversion.

Remarks

This conversion may silently lose precision, but will throw OverflowException if the value is out of range of decimal. Use ToDecimal(LossOfPrecisionHandling) passing in Throw for the second argument to avoid any information loss.

implicit operator PgNumeric(decimal)

public static implicit operator PgNumeric(decimal value)

Implicit conversion from decimal to PgNumeric.

Parameter
NameDescription
valuedecimal

The decimal value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

implicit operator PgNumeric(int)

public static implicit operator PgNumeric(int value)

Implicit conversion from int to PgNumeric.

Parameter
NameDescription
valueint

The integer value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

Remarks

This conversion exists to avoid ambiguity between the 64-bit conversions when using an integer literal.

implicit operator PgNumeric(long)

public static implicit operator PgNumeric(long value)

Implicit conversion from long to PgNumeric.

Parameter
NameDescription
valuelong

The integer value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

implicit operator PgNumeric(ulong)

public static implicit operator PgNumeric(ulong value)

Implicit conversion from ulong to PgNumeric.

Parameter
NameDescription
valueulong

The integer value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

operator !=(PgNumeric, PgNumeric)

public static bool operator !=(PgNumeric lhs, PgNumeric rhs)

Compares two values for inequality.

Parameters
NameDescription
lhsPgNumeric

The first value to compare.

rhsPgNumeric

The second value to compare.

Returns
TypeDescription
bool

false if the two arguments are equal; true otherwise.