-
Notifications
You must be signed in to change notification settings - Fork 0
Double Extensions
This utility library provides extension methods for double precision floating-point numbers to perform various operations.
Calculates the percentage of a double value relative to another double value.
double part = // initialize your double value;
double whole = // initialize your double value;
double percentage = part.PercentageOf(whole);Parameters:
-
part: The double value for which the percentage is calculated. -
whole: The double value representing the whole or total.
Returns:
-
percentage: Adoublevalue representing the percentage of thepartrelative to thewhole.
Calculates the absolute value of a double precision floating-point number.
using UtilityLibrary.Core;
double value = -3.14;
double absoluteValue = value.Abs();-
value(double): The double precision floating-point number.
- double: The absolute value of the input double precision floating-point number.
Calculates the absolute values of each element in a sequence of double precision floating-point numbers.
using System.Collections.Generic;
using UtilityLibrary.Core;
IEnumerable<double> values = new List<double> { -3.14, 2.71, -1.0 };
IEnumerable<double> absoluteValues = values.Abs();-
value(IEnumerable): The sequence of double precision floating-point numbers.
- IEnumerable: The sequence of absolute values.
Rounds a double precision floating-point number to a specified number of decimal points.
using UtilityLibrary.Core;
double value = 3.14159;
int decimalPoints = 2;
double roundedValue = value.RoundDecimalPoints(decimalPoints);-
value(double): The double precision floating-point number to round. -
decimalPoints(int): The number of decimal points to round to.
- double: The rounded double precision floating-point number.
Rounds a double precision floating-point number to two decimal points.
using UtilityLibrary.Core;
double value = 3.14159;
double roundedValue = value.RoundToTwoDecimalPoints();-
value(double): The double precision floating-point number to round.
- double: The rounded double precision floating-point number.
Determines whether a double precision floating-point number is within a specified range.
using UtilityLibrary.Core;
double value = 5.5;
bool inRange = value.IsInRange(0, 10);-
value(double): The double precision floating-point number to check. -
minValue(double): The minimum value of the range. -
maxValue(double): The maximum value of the range.
- bool: True if the double precision floating-point number is within the range; otherwise, false.
Returns a double precision floating-point number if it is within a specified range; otherwise, returns a default value.
using UtilityLibrary.Core;
double value = 15.5;
double result = value.InRange(0, 10, 0);-
value(double): The double precision floating-point number to check. -
minValue(double): The minimum value of the range. -
maxValue(double): The maximum value of the range. -
defaultValue(double): The default value to return if the double precision floating-point number is not within the range.
- double: The double precision floating-point number if it is within the range; otherwise, the default value.
Converts a double precision floating-point number to a TimeSpan representing days.
using UtilityLibrary.Core;
double value = 3.5;
TimeSpan timeSpan = value.ToDays();-
value(double): The double precision floating-point number to convert.
- TimeSpan: A TimeSpan that represents the specified number of days.
Converts a double precision floating-point number to a TimeSpan representing hours.
using UtilityLibrary.Core;
double value = 24.75;
TimeSpan timeSpan = value.ToHours();-
value(double): The double precision floating-point number to convert.
- TimeSpan: A TimeSpan that represents the specified number of hours.
Converts a double precision floating-point number to a TimeSpan representing minutes.
using UtilityLibrary.Core;
double value = 123.45;
TimeSpan timeSpan = value.ToMinutes();-
value(double): The double precision floating-point number to convert.
- TimeSpan: A TimeSpan that represents the specified number of minutes.
Converts a double precision floating-point number to a TimeSpan representing seconds.
using UtilityLibrary.Core;
double value = 987.654;
TimeSpan timeSpan = value.ToSeconds();-
value(double): The double precision floating-point number to convert.
- TimeSpan: A TimeSpan that represents the specified number of seconds.
Converts a double precision floating-point number to a TimeSpan representing milliseconds.
using UtilityLibrary.Core;
double value = 1234.5678;
TimeSpan timeSpan = value.ToMilliseconds();-
value(double): The double precision floating-point number to convert.
- TimeSpan: A TimeSpan that represents the specified number of milliseconds.