UiNumber

References
[IoId("00000000-ae61-4a68-ad31-356dbdee157f")] [DebuggerDisplay("{ToStringFull(),nq}")] public sealed class UiNumber : IComparable<UiNumber>, IEquatable<UiNumber>, IStorable
A number with controllable limits and decimal places. This type of number is not fast, do not use it for actual mathematics.

Constructors

UiNumber

#
Create a new limited number.
public UiNumber(
decimals,
Number of decimals.
value,
Value.
lower,
Lower limit.
upper
Upper limit.
)

UiNumber

#
Create a new limitless Ui number.
public UiNumber(
decimals,
Number of decimals.
value
Value.
)

UiNumber

#
Deserialisation constructor.
public UiNumber(
reader
Reader to deserialise with.
)

Fields

MaxDecimals

#
Maximum allowed number of decimals.
public const int MaxDecimals = 12

MinDecimals

#
Minimum allowed number of decimals.
public const int MinDecimals = 0

Properties

Decimals

#
Gets the number of decimals this number supports.
public int Decimals { get; }

Epsilon

#
Gets the epsilon for the current accuracy.
public decimal Epsilon { get; }

HasLowerLimit

#
Gets whether this number is considered to have a lower limit.
public bool HasLowerLimit { get; }

HasUpperLimit

#
Gets whether this number is considered to have an upper limit.
public bool HasUpperLimit { get; }

Lower

#
Gets the lower limit for this number.
public decimal Lower { get; }

NormalisedValue

#
Gets the value as a normalised unit. This doesn't work too well if the number domain is _huge_.
public decimal NormalisedValue { get; }

One

#
Gets an unlimited one value with two decimal places.
public static UiNumber One { get; }

Range

#
Gets the limit range. Careful, if the number is not limited this value is probably just decimal.MaxValue.
public decimal Range { get; }

Tick

#
Gets the index of the tick for the current value.
public long Tick { get; }

Ticks

#
Gets the total amount of unique 'ticks' in the current range. This number may be larger than the actual accuracy the decimal type supports on the current range.
public long Ticks { get; }

Upper

#
Gets the upper limit for this number.
public decimal Upper { get; }

Value

#
Gets the value of this number.
public decimal Value { get; }

Zero

#
Gets an unlimited zero value with two decimal places.
public static UiNumber Zero { get; }

Methods

CompareTo

#
Compare this number with another. Only the value is taken into consideration.
public int CompareTo(
other
Number to compare against.
)
Sorting key.

ComputeSensibleLimits

#
Compute sensible limits for a value.
public static void ComputeSensibleLimits(
value,
Value to encompass.
out decimal
lower,
Lower limit.
out decimal
upper
Upper limit.
)

Decrement

#
Decrement this number by the smallest possible amount.
public UiNumber Decrement()
Decremented number, or the same number of decrementation is not possible.

DefaultEpsilon

#
Gets the epsilon for a given number of decimals.
public static decimal DefaultEpsilon(
decimals
)

Equals

#
Determines whether the specified object is equal to the current object.
public override bool Equals(
obj
)
True if the value of this number is equal to the supplied number.
Object.Equals

Equals

#
Gets whether this number is equal to some other number. Only values are considered in this equality.
public bool Equals(
other
Number to test against.
)
True if both numbers have the same value.

EqualsFull

#
Gets whether this number is equal to some other number. Value, limits and decimals are all taken into consideration.
public bool EqualsFull(
other
Number to test against.
)
True if both numbers are identical.

FormatValue

#
Format a value using the current decimal pattern.
public string FormatValue(
value
Value to format.
)
Formatted value.

GetHashCode

#
Serves as the default hash function.
public override int GetHashCode()
A hash code for the current object.

Increment

#
Increment this number by the smallest possible amount.
public UiNumber Increment()
Incremented number, or the same number of incrementation is not possible.

LimitValue

#
Constrain a value to the current lower and upper limits.
public decimal LimitValue(
value
Value to limit.
)
Limited value.

ProcessValue

#
Process a value by both limiting and rounding it.
public decimal ProcessValue(
value
Value to process.
)
Processed value.

RoundValue

#
Process a value by rounding it.
public decimal RoundValue(
value
Value to round.
)
Rounded value.

Standard

#
Create a standard UiNumber with range (-10, 10) with optional overrides.
public static UiNumber Standard(
lower = -10,
Lower limit.
upper = 10,
Upper limit.
value = 0,
Value.
decimals = 2
Decimals.
)

Store

#
This method is called whenever the instance is required to serialize itself.
public void Store(
writer
Writer object to serialize with.
)
Store

ToString

#
Returns a string that represents the current object.
public override string ToString()
A string that represents the current object.
Object.ToString

ToStringFull

#
Returns a string that represents the current object.
public string ToStringFull()
A string that represents the current object.

TryParse

#
Try and parse a string as a UiNumber.
public static bool TryParse(
text,
String to parse.
number,
Parsed number or null on failure.
out string
message
Reason for failure.
)
True on success or false on failure.

TryParse

#
Try and parse a string as a UiNumber.
public static bool TryParse(
text,
String to parse.
number
Parsed number or NaN on failure.
)
True on success or false on failure.

WithDecimals

#
Change the decimal count of this UiNumber.
public UiNumber WithDecimals(
decimals
New decimal count.
)
Modified ui number.

WithIndexedValue

#
Change the value of this number by specifying a new tick.
public UiNumber WithIndexedValue(
tick
New tick.
)
Modified number.

WithLimits

#
Change the limits of this number.
public UiNumber WithLimits(
lower,
New lower limit.
upper
New upper limit.
)
Modified number.

WithNormalisedValue

#
Change the value of this number.
public UiNumber WithNormalisedValue(
value
New value.
)
Modified number.

WithValue

#
Change the value of this number.
public UiNumber WithValue(
value
New value.
)
Modified number.

Operators

OperationResultDescription
decimal+UiNumberUiNumberAdd a decimal value to a number.
UiNumber+decimalUiNumberAdd a decimal value to a number.
decimal-UiNumberUiNumberSubtract a number from a decimal value.
UiNumber-decimalUiNumberSubtract a decimal value from a number.