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

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

UiNumber

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

UiNumber

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

Fields

MaxDecimals

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

MinDecimals

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

Properties

Decimals

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

Epsilon

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

HasLowerLimit

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

HasUpperLimit

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

Lower

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

NormalisedValue

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

One

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

Range

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

Tick

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

Ticks

#
public long Ticks { get; }
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.

Upper

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

Value

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

Zero

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

Methods

CompareTo

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

ComputeSensibleLimits

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

Decrement

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

DefaultEpsilon

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

Equals

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

Equals

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

EqualsFull

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

FormatValue

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

GetHashCode

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

Increment

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

LimitValue

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

ProcessValue

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

RoundValue

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

Standard

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

Store

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

ToString

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

ToStringFull

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

TryParse

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

TryParse

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

WithDecimals

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

WithIndexedValue

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

WithLimits

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

WithNormalisedValue

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

WithValue

#
public UiNumber WithValue(decimal value)
Change the value of this number.
value (decimal)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.