public struct SpannerNumeric : IEquatable<SpannerNumeric>, IComparable<SpannerNumeric>, IComparable
Reference documentation and code samples for the Google Cloud Spanner v1 API struct SpannerNumeric.
Representation of the Spanner NUMERIC type, which has 38 digits of precision, and a fixed scale of 9 decimal places to the right of the decimal point
Namespace
Google.Cloud.Spanner.V1Assembly
Google.Cloud.Spanner.V1.dll
Properties
Epsilon
public static readonly SpannerNumeric Epsilon { get; }
The smallest positive value for SpannerNumeric, equal to 0.000000001.
Property Value | |
---|---|
Type | Description |
SpannerNumeric |
MaxValue
public static readonly SpannerNumeric MaxValue { get; }
The maximum valid value for SpannerNumeric, equal to 99999999999999999999999999999.999999999.
Property Value | |
---|---|
Type | Description |
SpannerNumeric |
MinValue
public static readonly SpannerNumeric MinValue { get; }
The minimum valid value for SpannerNumeric, equal to -99999999999999999999999999999.999999999.
Property Value | |
---|---|
Type | Description |
SpannerNumeric |
Zero
public static readonly SpannerNumeric Zero { get; }
Zero represented as a SpannerNumeric. This is the default value for the type.
Property Value | |
---|---|
Type | Description |
SpannerNumeric |
Methods
CompareTo(SpannerNumeric)
public int CompareTo(SpannerNumeric other)
Compares this value with other
.
Parameter | |
---|---|
Name | Description |
other | SpannerNumeric The value to compare with this one |
Returns | |
---|---|
Type | Description |
System.Int32 | A negative integer if this value is less than |
FromDecimal(Decimal, LossOfPrecisionHandling)
public static SpannerNumeric FromDecimal(decimal value, LossOfPrecisionHandling lossOfPrecisionHandling)
Converts a Decimal value to SpannerNumeric,
Parameters | |
---|---|
Name | Description |
value | Decimal The value to convert |
lossOfPrecisionHandling | LossOfPrecisionHandling How to handle values with signficant digits that would be lost by the conversion. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The converted value. |
This conversion may silently lose precision, depending on lossOfPrecisionHandling
.
GetHashCode()
public override int GetHashCode()
Returns a hash code for this value.
Returns | |
---|---|
Type | Description |
System.Int32 | A hash code for this value. |
Parse(String)
public static SpannerNumeric Parse(string text)
Parses a textual representation as a SpannerNumeric.
Parameter | |
---|---|
Name | Description |
text | String The text to parse. Must not be null. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The parsed value. |
text
must be a representation of a decimal value which can be represented by SpannerNumeric,
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 SpannerNumeric. |
ToDecimal(LossOfPrecisionHandling)
public decimal ToDecimal(LossOfPrecisionHandling lossOfPrecisionHandling)
Converts this value to Decimal,
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 string ToString()
Returns a canonical string representation of this value. This always uses "." as a decimal point, and only includes as many decimal places as are required to completely represent the value. 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 SpannerNumeric)
public static bool TryParse(string text, out SpannerNumeric value)
Attempts to parse a textual representation of a SpannerNumeric value.
Parameters | |
---|---|
Name | Description |
text | String The text to parse. Must not be null. |
value | SpannerNumeric 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
Addition(SpannerNumeric, SpannerNumeric)
public static SpannerNumeric operator +(SpannerNumeric lhs, SpannerNumeric rhs)
Returns the result of adding two SpannerNumeric values together.
Parameters | |
---|---|
Name | Description |
lhs | SpannerNumeric The first value to add. |
rhs | SpannerNumeric The second value to add. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of adding the two values. |
Equality(SpannerNumeric, SpannerNumeric)
public static bool operator ==(SpannerNumeric lhs, SpannerNumeric rhs)
Compares two values for equality.
Parameters | |
---|---|
Name | Description |
lhs | SpannerNumeric The first value to compare. |
rhs | SpannerNumeric The second value to compare. |
Returns | |
---|---|
Type | Description |
Boolean |
|
Explicit(SpannerNumeric to Decimal)
public static explicit operator decimal (SpannerNumeric value)
Explicit conversion from SpannerNumeric to Decimal.
Parameter | |
---|---|
Name | Description |
value | SpannerNumeric 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.
Explicit(Decimal to SpannerNumeric)
public static explicit operator SpannerNumeric(decimal value)
Explicit conversion from Decimal to SpannerNumeric.
Parameter | |
---|---|
Name | Description |
value | Decimal The decimal value to convert. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of the conversion. |
This conversion may silently lose precision. Use FromDecimal(Decimal, LossOfPrecisionHandling) passing in Throw for the second argument to avoid any information loss.
Implicit(Int32 to SpannerNumeric)
public static implicit operator SpannerNumeric(int value)
Implicit conversion from System.Int32 to SpannerNumeric.
Parameter | |
---|---|
Name | Description |
value | System.Int32 The integer value to convert. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of the conversion. |
This conversion exists to avoid ambiguity between the 64-bit conversions when using an integer literal.
Implicit(Int64 to SpannerNumeric)
public static implicit operator SpannerNumeric(long value)
Implicit conversion from Int64 to SpannerNumeric.
Parameter | |
---|---|
Name | Description |
value | Int64 The integer value to convert. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of the conversion. |
Implicit(UInt64 to SpannerNumeric)
public static implicit operator SpannerNumeric(ulong value)
Implicit conversion from UInt64 to SpannerNumeric.
Parameter | |
---|---|
Name | Description |
value | UInt64 The integer value to convert. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of the conversion. |
Inequality(SpannerNumeric, SpannerNumeric)
public static bool operator !=(SpannerNumeric lhs, SpannerNumeric rhs)
Compares two values for inequality.
Parameters | |
---|---|
Name | Description |
lhs | SpannerNumeric The first value to compare. |
rhs | SpannerNumeric The second value to compare. |
Returns | |
---|---|
Type | Description |
Boolean |
|
Subtraction(SpannerNumeric, SpannerNumeric)
public static SpannerNumeric operator -(SpannerNumeric lhs, SpannerNumeric rhs)
Returns the result of subtracting one SpannerNumeric value from another.
Parameters | |
---|---|
Name | Description |
lhs | SpannerNumeric The value to subtract from. |
rhs | SpannerNumeric The value to subtract. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The result of subtracting |
UnaryNegation(SpannerNumeric)
public static SpannerNumeric operator -(SpannerNumeric value)
The unary negation operator.
Parameter | |
---|---|
Name | Description |
value | SpannerNumeric The value to negate. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The negation of |
UnaryPlus(SpannerNumeric)
public static SpannerNumeric operator +(SpannerNumeric value)
The unary plus operator, provided mainly for consistency.
Parameter | |
---|---|
Name | Description |
value | SpannerNumeric The value to return. |
Returns | |
---|---|
Type | Description |
SpannerNumeric | The original value. |
Explicit Interface Implementations
IComparable.CompareTo(Object)
int IComparable.CompareTo(object obj)
Implementation of CompareTo(Object) to compare two SpannerNumeric values.
Parameter | |
---|---|
Name | Description |
obj | System.Object The object to compare this value with. |
Returns | |
---|---|
Type | Description |
System.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 |
|