Google Cloud Spanner v1 API - Struct PgNumeric (4.2.0)

Stay organized with collections Save and categorize content based on your preferences.
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 readonly PgNumeric MaxValue { get; }

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

Property Value
TypeDescription
PgNumeric

MinValue

public static readonly PgNumeric MinValue { get; }

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

Property Value
TypeDescription
PgNumeric

NaN

public static readonly PgNumeric NaN { get; }

NaN (Not a number) represented as a PgNumeric.

Property Value
TypeDescription
PgNumeric

Zero

public static readonly PgNumeric Zero { get; }

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

Property Value
TypeDescription
PgNumeric

Methods

CompareTo(PgNumeric)

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

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 readonly int GetHashCode()
Returns
TypeDescription
Int32
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 readonly 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 readonly 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
Boolean

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

Equality(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
Boolean

true if the two arguments are equal; false otherwise.

Explicit(PgNumeric to Decimal)

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(Decimal to PgNumeric)

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(Int32 to PgNumeric)

public static implicit operator PgNumeric(int value)

Implicit conversion from Int32 to PgNumeric.

Parameter
NameDescription
valueInt32

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(Int64 to PgNumeric)

public static implicit operator PgNumeric(long value)

Implicit conversion from Int64 to PgNumeric.

Parameter
NameDescription
valueInt64

The integer value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

Implicit(UInt64 to PgNumeric)

public static implicit operator PgNumeric(ulong value)

Implicit conversion from UInt64 to PgNumeric.

Parameter
NameDescription
valueUInt64

The integer value to convert.

Returns
TypeDescription
PgNumeric

The result of the conversion.

Inequality(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
Boolean

false if the two arguments are equal; true otherwise.

Explicit Interface Implementations

IComparable.CompareTo(Object)

readonly int IComparable.CompareTo(object obj)

Implementation of CompareTo(Object) to compare two PgNumeric values.

Parameter
NameDescription
objObject

The object to compare this value with.

Returns
TypeDescription
Int32

The result of comparing this value with obj. obj is null, this method returns a value greater than 0.

Remarks

This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.

Exceptions
TypeDescription
ArgumentException

obj is non-null but does not refer to an instance of PgNumeric.