C# Class Nvelope.NumberExtensions

Datei anzeigen Open project: TrinityWestern/Nvelope

Public Methods

Method Description
AsPercentage ( this rate ) : string

Formats a rate as a percentage.

DivDown ( this a, int b ) : int

Integer division that always rounds down Equivilant to a/b in many languages. It complements the modulo operation.

GreaterOf ( int first, int second ) : int

Returns the passed-in value that is greatest. If both values are the same returns the first

Inc ( this start, int increment = 1 ) : IEnumerable

Starting at start, generate an infinite sequence of numbers, incrementing by increment. WARNING: Generates an infinite (or nearly infinite) sequence, so call Take() on this or something, or your program will be here forever.

IsAbout ( this number, decimal other, decimal precision ) : bool

Is number the same as other, to within precision ie, 1.01m.IsAbout(1.0m, .1m) means "is 1.01 equal 1.0 to within .1?"

IsEven ( this num ) : bool
IsOdd ( this num ) : bool
LesserOf ( int first, int second ) : int

Returns the passed-in value that is smallest. If both values are the same returns the first

Mod ( this a, int b ) : int

The integer modulo where the divisor's sign is maintained, not the the dividends. If the dividend's sign is maintained, it is typically called the remainder. For example, (-3).Mod(5) == 2, this is different from the `%` in C#.

PrintDecimal ( this o ) : string
RoundTo ( this number, int decimalPlaces, MidpointRounding roundingRule = MidpointRounding.AwayFromZero ) : decimal

A wrapper around Decimal.Round

Times ( this num, System.Action action ) : void

Perform some action num times

To ( this start, int end, int increment = null ) : IEnumerable

Get a list of numbers from start to end (inclusive), incrementing by increment

ToOrdinal ( this i ) : string

Converts 1 to 1st, 2 to 2nd, etc

Method Details

AsPercentage() public static method

Formats a rate as a percentage.
public static AsPercentage ( this rate ) : string
rate this The rate specified as decimal.
return string

DivDown() public static method

Integer division that always rounds down Equivilant to a/b in many languages. It complements the modulo operation.
public static DivDown ( this a, int b ) : int
a this
b int
return int

GreaterOf() public static method

Returns the passed-in value that is greatest. If both values are the same returns the first
public static GreaterOf ( int first, int second ) : int
first int
second int
return int

Inc() public static method

Starting at start, generate an infinite sequence of numbers, incrementing by increment. WARNING: Generates an infinite (or nearly infinite) sequence, so call Take() on this or something, or your program will be here forever.
public static Inc ( this start, int increment = 1 ) : IEnumerable
start this
increment int
return IEnumerable

IsAbout() public static method

Is number the same as other, to within precision ie, 1.01m.IsAbout(1.0m, .1m) means "is 1.01 equal 1.0 to within .1?"
public static IsAbout ( this number, decimal other, decimal precision ) : bool
number this
other decimal
precision decimal
return bool

IsEven() public static method

public static IsEven ( this num ) : bool
num this
return bool

IsOdd() public static method

public static IsOdd ( this num ) : bool
num this
return bool

LesserOf() public static method

Returns the passed-in value that is smallest. If both values are the same returns the first
public static LesserOf ( int first, int second ) : int
first int
second int
return int

Mod() public static method

The integer modulo where the divisor's sign is maintained, not the the dividends. If the dividend's sign is maintained, it is typically called the remainder. For example, (-3).Mod(5) == 2, this is different from the `%` in C#.
public static Mod ( this a, int b ) : int
a this
b int
return int

PrintDecimal() public static method

public static PrintDecimal ( this o ) : string
o this
return string

RoundTo() public static method

A wrapper around Decimal.Round
public static RoundTo ( this number, int decimalPlaces, MidpointRounding roundingRule = MidpointRounding.AwayFromZero ) : decimal
number this
decimalPlaces int
roundingRule MidpointRounding
return decimal

Times() public static method

Perform some action num times
public static Times ( this num, System.Action action ) : void
num this
action System.Action
return void

To() public static method

Get a list of numbers from start to end (inclusive), incrementing by increment
public static To ( this start, int end, int increment = null ) : IEnumerable
start this
end int
increment int defaults to 1 or -1
return IEnumerable

ToOrdinal() public static method

Converts 1 to 1st, 2 to 2nd, etc
public static ToOrdinal ( this i ) : string
i this
return string