-
Notifications
You must be signed in to change notification settings - Fork 0
Decimal Extensions
Andrzej Kebab edited this page Feb 4, 2024
·
2 revisions
This utility library provides extension methods for decimal numbers to perform various operations.
Calculates the percentage of a decimal value relative to another decimal value.
decimal part = // initialize your decimal value;
decimal whole = // initialize your decimal value;
float percentage = part.PercentageOf(whole);Parameters:
-
part: The decimal value for which the percentage is calculated. -
whole: The decimal value representing the whole or total.
Returns:
-
percentage: Adecimalvalue representing the percentage of thepartrelative to thewhole.
Calculates the absolute value of a decimal number.
using UtilityLibrary.Core;
decimal value = -3.14m;
decimal absoluteValue = value.Abs();-
value(decimal): The decimal number.
- decimal: The absolute value of the input decimal number.
Calculates the absolute values of each element in a sequence of decimal numbers.
using System.Collections.Generic;
using UtilityLibrary.Core;
IEnumerable<decimal> values = new List<decimal> { -3.14m, 2.71m, -1.0m };
IEnumerable<decimal> absoluteValues = values.Abs();-
value(IEnumerable): The sequence of decimal numbers.
- IEnumerable: The sequence of absolute values.
Rounds a decimal number to a specified number of decimal points.
using UtilityLibrary.Core;
decimal value = 3.14159m;
int decimalPoints = 2;
decimal roundedValue = value.RoundDecimalPoints(decimalPoints);-
value(decimal): The decimal number to round. -
decimalPoints(int): The number of decimal points to round to.
- decimal: The rounded decimal number.
Rounds a decimal number to two decimal points.
using UtilityLibrary.Core;
decimal value = 3.14159m;
decimal roundedValue = value.RoundToTwoDecimalPoints();-
value(decimal): The decimal number to round.
- decimal: The rounded decimal number.