-
Notifications
You must be signed in to change notification settings - Fork 0
Float Extensions
This utility library provides extension methods for float values to perform various operations.
Calculates the percentage of a float value relative to another float value.
float part = // initialize your float value;
float whole = // initialize your float value;
float percentage = part.PercentageOf(whole);Parameters:
-
part: The float value for which the percentage is calculated. -
whole: The float tvalue representing the whole or total.
Returns:
-
percentage: Afloatvalue representing the percentage of thepartrelative to thewhole.
Returns the absolute value of the given float value.
using UtilityLibrary.Core;
float value = -5.0f;
float absoluteValue = value.Abs();-
value(float): The float value to calculate the absolute value for.
- float: The absolute value of the float value.
Returns a sequence of absolute values for each float value in the given enumerable.
using UtilityLibrary.Core;
IEnumerable<float> values = new List<float> { -5.0f, 10.0f, -3.0f };
IEnumerable<float> absoluteValues = values.Abs();-
values(IEnumerable): The enumerable containing float values.
- IEnumerable: A sequence of absolute values for each float value in the input enumerable.
Clamps the float value to a minimum of 0.
using UtilityLibrary.Core;
float value = -5.0f;
float result = value.ClampMin0();-
value(float): The float value to clamp.
- float: The clamped value with a minimum of 0.
Clamps the float value to a specified minimum.
using UtilityLibrary.Core;
float value = -5.0f;
float min = 0.0f;
float result = value.ClampMin(min);-
value(float): The float value to clamp. -
min(float): The minimum value to clamp to.
- float: The clamped value with a minimum of the specified value.
Clamps the float value to a maximum of 0.
using UtilityLibrary.Core;
float value = 5.0f;
float result = value.ClampMax0();-
value(float): The float value to clamp.
- float: The clamped value with a maximum of 0.
Clamps the float value to a specified maximum.
using UtilityLibrary.Core;
float value = 15.0f;
float max = 10.0f;
float result = value.ClampMax(max);-
value(float): The float value to clamp. -
max(float): The maximum value to clamp to.
- float: The clamped value with a maximum of the specified value.
Clamps the float value to the range [0, 1].
using UtilityLibrary.Core;
float value = 1.5f;
float result = value.Clamp01();-
value(float): The float value to clamp.
- float: The clamped value within the range [0, 1].
Clamps the float value within a specified range.
using UtilityLibrary.Core;
float value = 15.0f;
float min = 10.0f;
float max = 20.0f;
float result = value.Clamp(min, max);-
value(float): The float value to clamp. -
min(float): The minimum value of the range. -
max(float): The maximum value of the range.
- float: The clamped value within the specified range.
Rounds a float value to a specified number of decimal points.
using UtilityLibrary.Core;
float value = 123.4567f;
int decimalPoints = 2;
float result = value.RoundDecimalPoints(decimalPoints);-
value(float): The float value to round. -
decimalPoints(int): The number of decimal points to round to.
- float: The rounded float value.
Rounds a float value to two decimal points.
using UtilityLibrary.Core;
float value = 123.4567f;
float result = value.RoundToTwoDecimalPoints();-
value(float): The float value to round.
- float: The rounded float value.
Determines whether a float value is within a specified range.
using UtilityLibrary.Core;
float value = 15.0f;
float minValue = 10.0f;
float maxValue = 20.0f;
bool isInRange = value.IsInRange(minValue, maxValue);-
value(float): The float value to check. -
min(float): The minimum value of the range. -
max(float): The maximum value of the range.
- bool:
Trueif the float value is within the range; otherwise,False.
Returns the float value if it is within a specified range; otherwise, returns a default value.
using UtilityLibrary.Core;
float value = 25.0f;
float minValue = 10.0f;
float maxValue = 20.0f;
float defaultValue = -1.0f;
float result = value.InRange(minValue, maxValue, defaultValue);-
value(float): The float value to check. -
min(float): The minimum value of the range. -
max(float): The maximum value of the range. -
defaultValue(float): The default value to return if the float value is not within the range.
- float: The float value if it is within the range; otherwise, the default value.
Converts a float value to a TimeSpan representing days.
using UtilityLibrary.Core;
float value = 2.5f;
TimeSpan result = value.ToDays();-
value(float): The float value to convert.
- TimeSpan: A TimeSpan that represents the specified number of days.
Converts a float value to a TimeSpan representing hours.
using UtilityLibrary.Core;
float value = 3.5f;
TimeSpan result = value.ToHours();-
value(float):
The float value to convert.
- TimeSpan: A TimeSpan that represents the specified number of hours.
Converts a float value to a TimeSpan representing minutes.
using UtilityLibrary.Core;
float value = 75.0f;
TimeSpan result = value.ToMinutes();-
value(float): The float value to convert.
- TimeSpan: A TimeSpan that represents the specified number of minutes.
Converts a float value to a TimeSpan representing seconds.
using UtilityLibrary.Core;
float value = 120.5f;
TimeSpan result = value.ToSeconds();-
value(float): The float value to convert.
- TimeSpan: A TimeSpan that represents the specified number of seconds.
Converts a float value to a TimeSpan representing milliseconds.
using UtilityLibrary.Core;
float value = 1500.75f;
TimeSpan result = value.ToMilliseconds();-
value(float): The float value to convert.
- TimeSpan: A TimeSpan that represents the specified number of milliseconds.