java.lang.Object
io.github.palexdev.materialfx.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.static doublemapOneRangeToAnother(double value, NumberRange<Double> fromRange, NumberRange<Double> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range.static floatmapOneRangeToAnother(float value, NumberRange<Float> fromRange, NumberRange<Float> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range.static intmapOneRangeToAnother(int value, NumberRange<Integer> fromRange, NumberRange<Integer> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range.static longmapOneRangeToAnother(long value, NumberRange<Long> fromRange, NumberRange<Long> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range.
-
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. -
mapOneRangeToAnother
public static double mapOneRangeToAnother(double value, NumberRange<Double> fromRange, NumberRange<Double> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range. For example let's say I have a value of 0 that can go from -100 to 100 and I want to convert the value to a range of 0 to 100, the converted value will be 50 (0 is at the middle in the -100-100 range, and 50 is at the middle in the 0-100 range). -
mapOneRangeToAnother
public static float mapOneRangeToAnother(float value, NumberRange<Float> fromRange, NumberRange<Float> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range. For example let's say I have a value of 0 that can go from -100 to 100 and I want to convert the value to a range of 0 to 100, the converted value will be 50 (0 is at the middle in the -100-100 range, and 50 is at the middle in the 0-100 range). -
mapOneRangeToAnother
public static int mapOneRangeToAnother(int value, NumberRange<Integer> fromRange, NumberRange<Integer> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range. For example let's say I have a value of 0 that can go from -100 to 100 and I want to convert the value to a range of 0 to 100, the converted value will be 50 (0 is at the middle in the -100-100 range, and 50 is at the middle in the 0-100 range). -
mapOneRangeToAnother
public static long mapOneRangeToAnother(long value, NumberRange<Long> fromRange, NumberRange<Long> toRange, int decimalPrecision) Given a certain value, the range of possible values, and a different range, converts the given value from its range to the given second range. For example let's say I have a value of 0 that can go from -100 to 100 and I want to convert the value to a range of 0 to 100, the converted value will be 50 (0 is at the middle in the -100-100 range, and 50 is at the middle in the 0-100 range). -
closestValueTo
Given a certain value, finds the closest value in the given numbers list. -
closestValueTo
Given a certain value, finds the closest value in the given numbers list. -
closestValueTo
Given a certain value, finds the closest value in the given numbers list. -
closestValueTo
Given a certain value, finds the closest value in the given numbers list. -
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. UsesThreadLocalRandom.nextDouble(double, double). -
getRandomFloat
public static float getRandomFloat()Returns a random float value between 0 and 1. UsesThreadLocalRandom.nextFloat() -
getRandomIntBetween
public static int getRandomIntBetween(int min, int max) Returns a random int value between the specified min-max range. UsesThreadLocalRandom.nextInt(int, int). -
getRandomLongBetween
public static long getRandomLongBetween(long min, long max) Returns a random long value between the specified min-max range. UsesThreadLocalRandom.nextLong(long, long). -
isEven
public static boolean isEven(int number) Checks if the given number is even or odd, just a convenience method for aesthetic.
-