Class NumberUtils
java.lang.Object
io.github.palexdev.mfxeffects.utils.NumberUtils
Utils class for working with numbers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double val, double min, double max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range.static floatclamp(float val, float min, float max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range.static intclamp(int val, int min, int max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range.static longclamp(long val, long min, long max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range.static doubleclosestValueTo(double val, List<Double> list) Given a certain value, finds the closest value in the given numbers list.static floatclosestValueTo(float val, List<Float> list) Given a certain value, finds the closest value in the given numbers list.static intclosestValueTo(int val, List<Integer> list) Given a certain value, finds the closest value in the given numbers list.static longclosestValueTo(long val, List<Long> list) Given a certain value, finds the closest value in the given numbers list.static doubleformatTo(double value, int decimalPrecision) Formats the given double value to have the given number of decimal places.static StringformatToString(double value, int decimalPrecision) Returns the given value as a string the specified number of decimal places.static doublegetRandomDoubleBetween(double min, double max) Returns a random double between the specified min-max range.static floatReturns a random float value between 0 and 1.static intgetRandomIntBetween(int min, int max) Returns a random int value between the specified min-max range.static longgetRandomLongBetween(long min, long max) Returns a random long value between the specified min-max range.static booleanisEven(int number) Checks if the given number is even or odd, just a convenience method for aesthetic.
-
Method Details
-
clamp
public static double clamp(double val, double min, double max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range. -
clamp
public static float clamp(float val, float min, float max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range. -
clamp
public static int clamp(int val, int min, int max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range. -
clamp
public static long clamp(long val, long min, long max) Limits the given value to the given min-max range by returning the nearest bound if it exceeds or val if it's in range. -
closestValueTo
-
closestValueTo
-
closestValueTo
-
closestValueTo
-
formatTo
public static double formatTo(double value, int decimalPrecision) Formats the given double value to have the given number of decimal places. -
formatToString
Returns the given value as a string the specified number of decimal places. -
getRandomDoubleBetween
public static double getRandomDoubleBetween(double min, double max) Returns a random double between the specified min-max range.
-
getRandomFloat
public static float getRandomFloat()Returns a random float value between 0 and 1.
-
getRandomIntBetween
public static int getRandomIntBetween(int min, int max) Returns a random int value between the specified min-max range.
-
getRandomLongBetween
public static long getRandomLongBetween(long min, long max) Returns a random long value between the specified min-max range.
-
isEven
public static boolean isEven(int number) Checks if the given number is even or odd, just a convenience method for aesthetic.
-