NumberExtensions Class

Provides extension methods for numeric types.

public static class NumberExtensions

Methods

NameDescription
MakeSameSignAs(decimal, decimal)Returns the absolute value of number with the sign of sign.
MakeSameSignAs(double, double)Returns the absolute value of number with the sign of sign.
MakeSameSignAs(int, int)Returns the absolute value of number with the sign of sign.
MakeSameSignAs(long, long)Returns the absolute value of number with the sign of sign.
MakeSameSignAs(float, float)Returns the absolute value of number with the sign of sign.
ToEnglishOrdinal(int)Converts an integer to its English ordinal representation (e.g., 1st, 2nd, 3rd).
ToEnglishOrdinal(int, IFormatProvider)Converts an integer to its English ordinal representation using the specified format provider.
ToFrenchOrdinal(int)Converts an integer to its French ordinal representation (e.g., 1er, 2e, 3e).
ToFrenchOrdinal(int, IFormatProvider)Converts an integer to its French ordinal representation using the specified format provider.
ToStringInvariant(byte)Converts the number to its string representation using the invariant culture.
ToStringInvariant(byte, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(decimal)Converts the number to its string representation using the invariant culture.
ToStringInvariant(decimal, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(double)Converts the number to its string representation using the invariant culture.
ToStringInvariant(double, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(Half)Converts the number to its string representation using the invariant culture.
ToStringInvariant(Half, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(short)Converts the number to its string representation using the invariant culture.
ToStringInvariant(short, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(int)Converts the number to its string representation using the invariant culture.
ToStringInvariant(int, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(long)Converts the number to its string representation using the invariant culture.
ToStringInvariant(long, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(sbyte)Converts the number to its string representation using the invariant culture.
ToStringInvariant(sbyte, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(float)Converts the number to its string representation using the invariant culture.
ToStringInvariant(float, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(ushort)Converts the number to its string representation using the invariant culture.
ToStringInvariant(ushort, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(uint)Converts the number to its string representation using the invariant culture.
ToStringInvariant(uint, string?)Converts the number to its string representation using the invariant culture and the specified format.
ToStringInvariant(ulong)Converts the number to its string representation using the invariant culture.
ToStringInvariant(ulong, string?)Converts the number to its string representation using the invariant culture and the specified format.

MakeSameSignAs overloads

MakeSameSignAs(decimal, decimal)

NumberExtensions.cs

Returns the absolute value of number with the sign of sign.

public static decimal MakeSameSignAs(this decimal number, decimal sign)
Parameters
number decimal
sign decimal
Returns

decimal

Remarks

A zero sign is positive, unless it is a negative zero, like Math.CopySign.

MakeSameSignAs(double, double)

NumberExtensions.cs

Returns the absolute value of number with the sign of sign.

public static double MakeSameSignAs(this double number, double sign)
Parameters
number double
sign double
Returns

double

MakeSameSignAs(int, int)

NumberExtensions.cs

Returns the absolute value of number with the sign of sign.

public static int MakeSameSignAs(this int number, int sign)
Parameters
number int
sign int
Returns

int

Exceptions
OverflowException
number is Int32.MinValue and sign is positive or zero.
Remarks

A zero sign is positive.

MakeSameSignAs(long, long)

NumberExtensions.cs

Returns the absolute value of number with the sign of sign.

public static long MakeSameSignAs(this long number, long sign)
Parameters
number long
sign long
Returns

long

Exceptions
OverflowException
number is Int64.MinValue and sign is positive or zero.
Remarks

A zero sign is positive.

MakeSameSignAs(float, float)

NumberExtensions.cs

Returns the absolute value of number with the sign of sign.

public static float MakeSameSignAs(this float number, float sign)
Parameters
number float
sign float
Returns

float

ToEnglishOrdinal overloads

ToEnglishOrdinal(int)

NumberExtensions.cs

Converts an integer to its English ordinal representation (e.g., 1st, 2nd, 3rd).

public static string ToEnglishOrdinal(int num)
Parameters
num int
Returns

string

ToEnglishOrdinal(int, IFormatProvider)

NumberExtensions.cs

Converts an integer to its English ordinal representation using the specified format provider.

public static string ToEnglishOrdinal(int num, IFormatProvider formatProvider)
Parameters
num int
formatProvider IFormatProvider
Returns

string

ToFrenchOrdinal overloads

ToFrenchOrdinal(int)

NumberExtensions.cs

Converts an integer to its French ordinal representation (e.g., 1er, 2e, 3e).

public static string ToFrenchOrdinal(int num)
Parameters
num int
Returns

string

ToFrenchOrdinal(int, IFormatProvider)

NumberExtensions.cs

Converts an integer to its French ordinal representation using the specified format provider.

public static string ToFrenchOrdinal(int num, IFormatProvider formatProvider)
Parameters
num int
formatProvider IFormatProvider
Returns

string

ToStringInvariant overloads

ToStringInvariant(byte)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this byte number)
Parameters
number byte
Returns

string

ToStringInvariant(byte, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this byte number, string? format)
Parameters
number byte
format string?
Returns

string

ToStringInvariant(decimal)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this decimal number)
Parameters
number decimal
Returns

string

ToStringInvariant(decimal, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this decimal number, string? format)
Parameters
number decimal
format string?
Returns

string

ToStringInvariant(double)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this double number)
Parameters
number double
Returns

string

ToStringInvariant(double, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this double number, string? format)
Parameters
number double
format string?
Returns

string

ToStringInvariant(Half)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this Half number)
Parameters
number Half
Returns

string

ToStringInvariant(Half, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this Half number, string? format)
Parameters
number Half
format string?
Returns

string

ToStringInvariant(short)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this short number)
Parameters
number short
Returns

string

ToStringInvariant(short, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this short number, string? format)
Parameters
number short
format string?
Returns

string

ToStringInvariant(int)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this int number)
Parameters
number int
Returns

string

ToStringInvariant(int, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this int number, string? format)
Parameters
number int
format string?
Returns

string

ToStringInvariant(long)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this long number)
Parameters
number long
Returns

string

ToStringInvariant(long, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this long number, string? format)
Parameters
number long
format string?
Returns

string

ToStringInvariant(sbyte)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this sbyte number)
Parameters
number sbyte
Returns

string

ToStringInvariant(sbyte, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this sbyte number, string? format)
Parameters
number sbyte
format string?
Returns

string

ToStringInvariant(float)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this float number)
Parameters
number float
Returns

string

ToStringInvariant(float, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this float number, string? format)
Parameters
number float
format string?
Returns

string

ToStringInvariant(ushort)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this ushort number)
Parameters
number ushort
Returns

string

ToStringInvariant(ushort, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this ushort number, string? format)
Parameters
number ushort
format string?
Returns

string

ToStringInvariant(uint)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this uint number)
Parameters
number uint
Returns

string

ToStringInvariant(uint, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this uint number, string? format)
Parameters
number uint
format string?
Returns

string

ToStringInvariant(ulong)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture.

public static string ToStringInvariant(this ulong number)
Parameters
number ulong
Returns

string

ToStringInvariant(ulong, string?)

NumberExtensions.cs

Converts the number to its string representation using the invariant culture and the specified format.

public static string ToStringInvariant(this ulong number, string? format)
Parameters
number ulong
format string?
Returns

string