Class FloatExtensions
Inheritance
object
FloatExtensions
Namespace: TetraCreations.Core
Assembly: cs.temp.dll.dll
Syntax
public static class FloatExtensions
Methods
Clamp(ref float, float, float)
Clamp the float value by reference.
Declaration
public static void Clamp(this ref float value, float minimum, float maximum)
Parameters
Type |
Name |
Description |
float |
value |
Value to clamp
|
float |
minimum |
Minimum value
|
float |
maximum |
Maximum value
|
CountDigits(float, int, bool)
Returns the number of digit of a floating number regardless of the current CultureInfo.
Declaration
public static int CountDigits(this float value, int precisionLimit = 7, bool countTrailingZeroes = true)
Parameters
Type |
Name |
Description |
float |
value |
|
int |
precisionLimit |
|
bool |
countTrailingZeroes |
|
Returns
GetPercentage(float, float)
Get the percentage of the value for example : 50.GetPercentage(20) = 50 * 0.2 = 10
Declaration
public static float GetPercentage(this float value, float percentage)
Parameters
Type |
Name |
Description |
float |
value |
|
float |
percentage |
|
Returns
IsApproximatelyEquals(float, float, float)
Checks if two floating numbers are close enough
Declaration
public static bool IsApproximatelyEquals(float a, float b, float tolerance = 0.001)
Parameters
Type |
Name |
Description |
float |
a |
|
float |
b |
|
float |
tolerance |
How much difference we can have between the two floating value to consider them equals.
|
Returns
NormalizeEulerAngle(float)
Normalize euler angle value from 0 to 360.
Declaration
public static float NormalizeEulerAngle(this float angle)
Parameters
Type |
Name |
Description |
float |
angle |
|
Returns
ParseToInt(float, RoundMethod)
Converts a floating number to an int using one of the desired method : Ceiling, Floor, Round
Declaration
public static int ParseToInt(this float value, RoundMethod roundMethod = RoundMethod.Round)
Parameters
Type |
Name |
Description |
float |
value |
|
RoundMethod |
roundMethod |
|
Returns
PercentageOf(float, int)
Returns the percentage represented by a number depending on a total for exemple 50 in 125 is 40%.
Declaration
public static float PercentageOf(this float portion, int total)
Parameters
Type |
Name |
Description |
float |
portion |
|
int |
total |
|
Returns
Round(float, int, MidpointRounding)
Round a floating number to the desired amount of digit.
Declaration
public static float Round(this float value, int digitCount = 2, MidpointRounding midpointRounding = null)
Parameters
Type |
Name |
Description |
float |
value |
|
int |
digitCount |
|
MidpointRounding |
midpointRounding |
|
Returns
ToMultiplierPercentageBonus(float, int, bool)
Returns a string representing a multiplier bonus percentage, asssuming 1f is 0%.
So any value above 1f for example 1.25f will return +25%. And any value below 1f, like 0.25f will return -75%.
Declaration
public static string ToMultiplierPercentageBonus(this float value, int digit = 0, bool withPositiveSign = true)
Parameters
Type |
Name |
Description |
float |
value |
|
int |
digit |
Number of digit.
|
bool |
withPositiveSign |
Add "+" sign in front of a positive percentage.
|
Returns
ToStringPercentage(float, string)
Converts the float to string percentage
Example 0.45f ToPercentage() will return 45%
Declaration
public static string ToStringPercentage(this float value, string precision = "0")
Parameters
Type |
Name |
Description |
float |
value |
|
string |
precision |
Number of digit.
|
Returns