Class NumberUtility
This utility class is designed to make number operations easier to work with.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class NumberUtility
Methods
| Improve this DocBytesToGigabytes(Int64)
Converts the specified bytes
to its equivalent representation in gigabytes.
Declaration
public static double BytesToGigabytes(long bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | bytes | The bytes to be converted. |
Returns
Type | Description |
---|---|
System.Double | A gigabyte representation equivalent to the specified |
BytesToKilobytes(Int64)
Converts the specified bytes
to its equivalent representation in kilobytes.
Declaration
public static double BytesToKilobytes(long bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | bytes | The bytes to be converted. |
Returns
Type | Description |
---|---|
System.Double | A kilobyte representation equivalent to the specified |
BytesToMegabytes(Int64)
Converts the specified bytes
to its equivalent representation in megabytes.
Declaration
public static double BytesToMegabytes(long bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | bytes | The bytes to be converted. |
Returns
Type | Description |
---|---|
System.Double | A megabyte representation equivalent to the specified |
BytesToTerabytes(Int64)
Converts the specified bytes
to its equivalent representation in terabytes.
Declaration
public static double BytesToTerabytes(long bytes)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | bytes | The bytes to be converted. |
Returns
Type | Description |
---|---|
System.Double | A terabyte representation equivalent to the specified |
Factorial(Double)
Calculates the factorial of a positive integer n
denoted by n!.
Declaration
public static double Factorial(double n)
Parameters
Type | Name | Description |
---|---|---|
System.Double | n | The positive integer to calculate a factorial number by. |
Returns
Type | Description |
---|---|
System.Double | The factorial number calculated from |
GetHighestValue(Decimal[])
Gets the highest System.Decimal value of the specified System.Decimal values.
Declaration
public static decimal GetHighestValue(params decimal[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Decimal[] | values | A variable number of System.Decimal values to parse for the highest value. |
Returns
Type | Description |
---|---|
System.Decimal | The highest System.Decimal value of the specified System.Decimal values. |
GetHighestValue(Double[])
Gets the highest System.Double value of the specified System.Double values.
Declaration
public static double GetHighestValue(params double[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | values | A variable number of System.Double values to parse for the highest value. |
Returns
Type | Description |
---|---|
System.Double | The highest System.Double value of the specified System.Double values. |
GetHighestValue(Int32[])
Gets the highest System.Int32 value of the specified System.Int32 values.
Declaration
public static int GetHighestValue(params int[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | values | A variable number of System.Int32 values to parse for the highest value. |
Returns
Type | Description |
---|---|
System.Int32 | The highest System.Int32 value of the specified System.Int32 values. |
GetHighestValue(Int64[])
Gets the highest System.Int64 value of the specified System.Int64 values.
Declaration
public static long GetHighestValue(params long[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | values | A variable number of System.Int64 values to parse for the highest value. |
Returns
Type | Description |
---|---|
System.Int64 | The highest System.Int64 value of the specified System.Int64 values. |
GetLowestValue(Decimal[])
Gets the lowest System.Decimal value of the specified System.Decimal values.
Declaration
public static decimal GetLowestValue(params decimal[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Decimal[] | values | A variable number of System.Decimal values to parse for the lowest value. |
Returns
Type | Description |
---|---|
System.Decimal | The lowest System.Decimal value of the specified System.Decimal values. |
GetLowestValue(Double[])
Gets the lowest System.Double value of the specified System.Double values.
Declaration
public static double GetLowestValue(params double[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | values | A variable number of System.Double values to parse for the lowest value. |
Returns
Type | Description |
---|---|
System.Double | The lowest System.Double value of the specified System.Double values. |
GetLowestValue(Int32[])
Gets the lowest System.Int32 value of the specified System.Int32 values.
Declaration
public static int GetLowestValue(params int[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | values | A variable number of System.Int32 values to parse for the lowest value. |
Returns
Type | Description |
---|---|
System.Int32 | The lowest System.Int32 value of the specified System.Int32 values. |
GetLowestValue(Int64[])
Gets the lowest System.Int64 value of the specified System.Int64 values.
Declaration
public static long GetLowestValue(params long[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | values | A variable number of System.Int64 values to parse for the lowest value. |
Returns
Type | Description |
---|---|
System.Int64 | The lowest System.Int64 value of the specified System.Int64 values. |
GetRandomNumber()
Generates a nonnegative random number.
Declaration
public static int GetRandomNumber()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to zero and less than System.Int32.MaxValue. |
GetRandomNumber(Int32)
Generates a nonnegative random number less than the specified maximum.
Declaration
public static int GetRandomNumber(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxValue | The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero. |
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to zero, and less than maxValue; that is, the range of return values ordinarily includes zero but not maxValue. However, if maxValue equals zero, maxValue is returned. |
GetRandomNumber(Int32, Int32)
Generates a random number within a specified range.
Declaration
public static int GetRandomNumber(int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minValue | The inclusive lower bound of the random number returned. |
System.Int32 | maxValue | The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue. |
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned. |
GetRandomNumber(Int32, Int32, RandomSeverity)
Generates a random number within a specified range.
Declaration
public static int GetRandomNumber(int minValue, int maxValue, RandomSeverity severity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minValue | The inclusive lower bound of the random number returned. |
System.Int32 | maxValue | The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue. |
RandomSeverity | severity | The severity of the random number being generated. |
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned. |
IsCountableSequence(IEnumerable<Int32>)
Determines whether the specified source
is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence).
Declaration
public static bool IsCountableSequence(IEnumerable<int> source)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Int32> | source | The value to test for a sequence of countable characters. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsCountableSequence(IEnumerable<Int64>)
Determines whether the specified source
is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence).
Declaration
public static bool IsCountableSequence(IEnumerable<long> source)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Int64> | source | The value to test for a sequence of countable characters. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsEven(Int32)
Determines whether the specified value
is an even number.
Declaration
public static bool IsEven(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value to evaluate. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsOdd(Int32)
Determines whether the specified value
is an odd number.
Declaration
public static bool IsOdd(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value to evaluate. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsPrime(Int32)
Determines whether the specified value
is a prime number.
Declaration
public static bool IsPrime(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The positive integer to determine whether is a prime number. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
RoundOff(Double, RoundOffAccuracy)
Rounds a double-precision floating-point value to the nearest integral value closest to the specified accuracy
.
Declaration
public static double RoundOff(double value, RoundOffAccuracy accuracy)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | A double-precision floating-point number to be rounded. |
RoundOffAccuracy | accuracy | The accuracy to use in the rounding. |
Returns
Type | Description |
---|---|
System.Double | The integer value closest to the specified |