public readonly struct PgNumeric : IEquatable<PgNumeric>, IComparable<PgNumeric>, IComparable
Representation of PostgreSQL numeric type which has max precision of 147455 and a max scale of 16383.
Namespace
Google.Cloud.Spanner.V1Assembly
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 | |
---|---|
Type | Description |
PgNumeric |
MinValue
public static readonly PgNumeric MinValue { get; }
The minimum valid value for PgNumeric, equal to -(BigInteger.Pow(10, 147455) - 1)
Property Value | |
---|---|
Type | Description |
PgNumeric |
NaN
public static readonly PgNumeric NaN { get; }
NaN (Not a number) represented as a PgNumeric.
Property Value | |
---|---|
Type | Description |
PgNumeric |
Zero
public static readonly PgNumeric Zero { get; }
Zero represented as a PgNumeric. This is the default value for the type.
Property Value | |
---|---|
Type | Description |
PgNumeric |
Methods
CompareTo(PgNumeric)
public readonly int CompareTo(PgNumeric other)
Parameter | |
---|---|
Name | Description |
other | PgNumeric |
Returns | |
---|---|
Type | Description |
Int32 |
FromDecimal(Decimal)
public static PgNumeric FromDecimal(decimal value)
Parameter | |
---|---|
Name | Description |
value | Decimal The value to convert |
Returns | |
---|---|
Type | Description |
PgNumeric | The converted value. |
GetHashCode()
public override readonly int GetHashCode()
Returns | |
---|---|
Type | Description |
Int32 |
Parse(String)
public static PgNumeric Parse(string text)
Parses a textual representation as a PgNumeric.
Parameter | |
---|---|
Name | Description |
text | String The text to parse. Must not be null. |
Returns | |
---|---|
Type | Description |
PgNumeric | The parsed value. |
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 | |
---|---|
Type | Description |
FormatException | The value could not be parsed as a PgNumeric. |
ToDecimal(LossOfPrecisionHandling)
public readonly decimal ToDecimal(LossOfPrecisionHandling lossOfPrecisionHandling)
Converts this value to PgNumeric,
Parameter | |
---|---|
Name | Description |
lossOfPrecisionHandling | LossOfPrecisionHandling How to handle values with signficant digits that would be lost by the conversion. |
Returns | |
---|---|
Type | Description |
Decimal | The converted value. |
This conversion may silently lose precision, depending on lossOfPrecisionHandling
, but
will always throw OverflowException if value is out of the range of Decimal.
Exceptions | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
String | A canonical string representation of this value. |
TryParse(String, out PgNumeric)
public static bool TryParse(string text, out PgNumeric value)
Attempts to parse a textual representation of a PgNumeric value.
Parameters | |
---|---|
Name | Description |
text | String The text to parse. Must not be null. |
value | PgNumeric The parsed value, or 0 on failure. |
Returns | |
---|---|
Type | Description |
Boolean |
|
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 | |
---|---|
Name | Description |
lhs | PgNumeric The first value to compare. |
rhs | PgNumeric The second value to compare. |
Returns | |
---|---|
Type | Description |
Boolean |
|
Explicit(PgNumeric to Decimal)
public static explicit operator decimal (PgNumeric value)
Parameter | |
---|---|
Name | Description |
value | PgNumeric The numeric value to convert. |
Returns | |
---|---|
Type | Description |
Decimal | The result of the conversion. |
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)
Parameter | |
---|---|
Name | Description |
value | Decimal The decimal value to convert. |
Returns | |
---|---|
Type | Description |
PgNumeric | The result of the conversion. |
Implicit(Int32 to PgNumeric)
public static implicit operator PgNumeric(int value)
Parameter | |
---|---|
Name | Description |
value | Int32 The integer value to convert. |
Returns | |
---|---|
Type | Description |
PgNumeric | The result of the conversion. |
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)
Parameter | |
---|---|
Name | Description |
value | Int64 The integer value to convert. |
Returns | |
---|---|
Type | Description |
PgNumeric | The result of the conversion. |
Implicit(UInt64 to PgNumeric)
public static implicit operator PgNumeric(ulong value)
Parameter | |
---|---|
Name | Description |
value | UInt64 The integer value to convert. |
Returns | |
---|---|
Type | Description |
PgNumeric | The result of the conversion. |
Inequality(PgNumeric, PgNumeric)
public static bool operator !=(PgNumeric lhs, PgNumeric rhs)
Compares two values for inequality.
Parameters | |
---|---|
Name | Description |
lhs | PgNumeric The first value to compare. |
rhs | PgNumeric The second value to compare. |
Returns | |
---|---|
Type | Description |
Boolean |
|
Explicit Interface Implementations
IComparable.CompareTo(Object)
readonly int IComparable.CompareTo(object obj)
Implementation of CompareTo(Object) to compare two PgNumeric values.
Parameter | |
---|---|
Name | Description |
obj | Object The object to compare this value with. |
Returns | |
---|---|
Type | Description |
Int32 | The result of comparing this value with |
This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.
Exceptions | |
---|---|
Type | Description |
ArgumentException |
|