Class NH
- Namespace
- SunamoNumbers
- Assembly
- SunamoNumbers.dll
Number Helper - provides statistical calculations, interval generation, and numeric utilities.
public static class NH
- Inheritance
-
NH
- Inherited Members
Methods
Average(double, double)
Calculates the average of two double values.
public static double Average(double totalValue, double count)
Parameters
Returns
AverageFloat(double, double)
Calculates the average of two values and returns the result as float.
public static float AverageFloat(double totalValue, double count)
Parameters
Returns
Average<T>(List<T>)
Calculates the average of all values in a list.
public static T Average<T>(List<T> list)
Parameters
listList<T>The list of values to average.
Returns
- T
Type Parameters
TThe numeric type.
Average<T>(dynamic, dynamic)
Calculates the average by dividing the total value by the count.
public static T Average<T>(dynamic totalValue, dynamic count)
Parameters
totalValuedynamicThe total value (dividend).
countdynamicThe count to divide by (divisor).
Returns
- T
Type Parameters
TThe numeric type.
CalculateMedianAverage(Dictionary<string, List<float>>, bool)
Calculates median and average statistics for categorized float values.
public static string CalculateMedianAverage(Dictionary<string, List<float>> dictionary, bool shouldThrowOnSingleElement)
Parameters
dictionaryDictionary<string, List<float>>A dictionary mapping category names to lists of float values.
shouldThrowOnSingleElementboolWhether to throw an exception if a category has only one element.
Returns
CalculateMedianAverage(List<double>, out MedianAverage<double>, bool)
Calculates median and average statistics for a list of doubles with full output.
public static string CalculateMedianAverage(List<double> list, out MedianAverage<double> medianAverage, bool shouldThrowOnSingleElement)
Parameters
listList<double>The list of double values (zeroes will be removed).
medianAverageMedianAverage<double>The output containing all calculated statistical values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverage(List<double>, bool)
Calculates median and average statistics for a list of doubles.
public static string CalculateMedianAverage(List<double> list, bool shouldThrowOnSingleElement)
Parameters
listList<double>The list of double values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverage(List<long>, bool)
Calculates median and average statistics for a list of longs.
public static string CalculateMedianAverage(List<long> list, bool shouldThrowOnSingleElement)
Parameters
listList<long>The list of long values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverage(List<float>, out MedianAverage<double>, bool)
Calculates median and average statistics for a list of floats.
public static string CalculateMedianAverage(List<float> list, out MedianAverage<double> medianAverage, bool shouldThrowOnSingleElement)
Parameters
listList<float>The list of float values.
medianAverageMedianAverage<double>The output containing all calculated statistical values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverageNoOut(List<float>, bool)
Calculates median and average statistics without an out parameter.
public static (string, MedianAverage<double>) CalculateMedianAverageNoOut(List<float> list, bool shouldThrowOnSingleElement)
Parameters
listList<float>The list of float values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverageNoOutDouble(List<double>, bool)
Calculates median and average statistics for a list of doubles without an out parameter.
public static (string, MedianAverage<double>) CalculateMedianAverageNoOutDouble(List<double> list, bool shouldThrowOnSingleElement)
Parameters
listList<double>The list of double values.
shouldThrowOnSingleElementboolWhether to throw an exception if the list has only one element.
Returns
CalculateMedianAverageT(List<double>, out MedianAverage<double>)
Calculates median and average statistics for a list of doubles.
public static string CalculateMedianAverageT(List<double> list, out MedianAverage<double> medianAverage)
Parameters
listList<double>The list of double values (zeroes will be removed).
medianAverageMedianAverage<double>The output containing all calculated statistical values.
Returns
Divide(object, object)
Casts both values to double and divides the first by the second.
public static double Divide(object dividend, object divisor)
Parameters
Returns
GenerateIntervalByte(byte, byte)
Generates an inclusive byte interval from the start value to the end value.
public static List<byte> GenerateIntervalByte(byte from, byte to)
Parameters
Returns
GenerateIntervalInt(int, int)
Generates an inclusive integer interval from the start value to the end value.
public static List<int> GenerateIntervalInt(int from, int to)
Parameters
Returns
GenerateIntervalShort(short, short)
Generates an inclusive short interval from the start value to the end value.
public static List<short> GenerateIntervalShort(short from, short to)
Parameters
Returns
GetLowest(List<int>, List<int>)
Gets the lowest value from the list that is not in the excluded values.
public static int GetLowest(List<int> excludedValues, List<int> list)
Parameters
excludedValuesList<int>The list of values to exclude.
listList<int>The list of values to search.
Returns
Invert(List<int>, int, int)
Creates an inverted list where missing indices are filled with a default value.
public static List<int> Invert(List<int> list, int defaultValue, int count)
Parameters
listList<int>The source list of integer values.
defaultValueintThe value to use for indices not present in the source list.
countintThe total number of elements in the result.
Returns
JoinAnotherTokensIfIsNumber(List<string>, int)
Joins consecutive numeric tokens starting at the specified index into a single number string.
public static string JoinAnotherTokensIfIsNumber(List<string> list, int startIndex)
Parameters
Returns
Last2NumberByte(int)
Extracts the last 2 digits of a year as a byte. Reversion is DTHelperGeneral.FullYear.
public static byte Last2NumberByte(int year)
Parameters
yearintThe full year value.
Returns
MakeUpTo2NumbersToZero(byte)
Pads a byte number to 2 digits with leading zero if needed.
public static string MakeUpTo2NumbersToZero(byte number)
Parameters
numberbyteThe byte number to pad.
Returns
MakeUpTo2NumbersToZero(int)
Pads an integer number to 2 digits with leading zero if needed.
public static string MakeUpTo2NumbersToZero(int number)
Parameters
numberintThe integer number to pad.
Returns
MakeUpTo3NumbersToZero(int)
Pads an integer number to 3 digits with leading zeroes if needed.
public static string MakeUpTo3NumbersToZero(int number)
Parameters
numberintThe number to pad.
Returns
Max(List<int>)
Finds the maximum value in a list of integers.
public static int Max(List<int> list)
Parameters
Returns
MaxForLength(int)
Returns the maximum integer value that has the specified digit length.
public static int MaxForLength(int length = 4)
Parameters
lengthintThe number of digits.
Returns
Median2<T>(IList<T>)
Computes the median value using sorting. The list is not mutated.
public static double Median2<T>(IList<T> list)
Parameters
listIList<T>The list to compute the median for.
Returns
Type Parameters
TThe element type.
Median<T>(IList<T>)
Computes the median value of a list. The list may be mutated during computation.
public static T Median<T>(this IList<T> list) where T : IComparable<T>
Parameters
listIList<T>The list to compute the median for.
Returns
- T
Type Parameters
TThe element type.
Median<T>(IList<T>, Func<T, double>)
Computes the median value of a sequence using a value selector function.
public static double Median<T>(this IList<T> list, Func<T, double> getValue)
Parameters
listIList<T>The list to compute the median for.
getValueFunc<T, double>The function to extract a double value from each element.
Returns
Type Parameters
TThe element type.
Min(List<int>)
Finds the minimum value in a list of integers.
public static int Min(List<int> list)
Parameters
Returns
MinForLength(int)
Returns the minimum integer value that has the specified digit length.
public static int MinForLength(int length = 4)
Parameters
lengthintThe number of digits.
Returns
NumberIntUntilWontReachOtherChar(string)
Extracts leading digits from a string until a non-digit character is encountered.
public static (int, string) NumberIntUntilWontReachOtherChar(string text)
Parameters
textstringThe input text.
Returns
RemoveEndingZeroPadding(List<byte>)
Removes trailing zero bytes from the end of a byte list.
public static void RemoveEndingZeroPadding(List<byte> list)
Parameters
ReturnTheNearestSmallIntegerNumber(double)
Returns the nearest integer value for a double (rounds to nearest).
public static double ReturnTheNearestSmallIntegerNumber(double value)
Parameters
valuedoubleThe double value to convert.
Returns
Round0(float)
Rounds a float value to zero decimal places and returns as string.
public static string Round0(float value)
Parameters
valuefloatThe float value to round.
Returns
RoundAndReturnInInputType(float, int)
Rounds a float value to the specified number of decimal places and returns the result as float.
public static float RoundAndReturnInInputType(float value, int decimalPlaces)
Parameters
Returns
Sort<T>(params T[])
Sorts the provided values and returns them as a sorted list.
public static List<T> Sort<T>(params T[] values)
Parameters
valuesT[]The values to sort.
Returns
- List<T>
Type Parameters
TThe type of the values.
Sum(List<string>)
Sums all values in a list of string-represented numbers.
public static double Sum(List<string> list)
Parameters
Returns
Sum<T>(List<T>)
Sums all values in a generic list using dynamic dispatch.
public static T Sum<T>(List<T> list)
Parameters
listList<T>The list of values to sum.
Returns
- T
Type Parameters
TThe numeric type.