Package adams.data
Class RoundingUtils
- java.lang.Object
-
- adams.data.RoundingUtils
-
public class RoundingUtils extends Object
Helper class for rounding.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description RoundingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleapply(RoundingType type, double value, int decimals)Apply the specified rounding type.static floatapply(RoundingType type, float value, int decimals)Apply the specified rounding type.static doubleceil(double value, int decimals)Round up to specific number of digits after decimal point.static floatceil(float value, int decimals)Round up to specific number of digits after decimal point.protected static StringfixDecimals(String s, int decimals)Fixes rounding issues, ensuring that only the specified number of decimals get returned.static doublefloor(double value, int decimals)Round down to specific number of digits after decimal point.static floatfloor(float value, int decimals)Round down to specific number of digits after decimal point.static doublerint(double value, int decimals)Round (to nearest integer) to specific number of digits after decimal point.static floatrint(float value, int decimals)Round (to nearest integer) to specific number of digits after decimal point.static doubleround(double value, int decimals)Round to specific number of digits after decimal point.static floatround(float value, int decimals)Round to specific number of digits after decimal point.static StringtoString(RoundingType type, double value, int decimals)Apply the specified rounding type and generates a string.static StringtoString(RoundingType type, float value, int decimals)Apply the specified rounding type and generates a string.
-
-
-
Method Detail
-
round
public static double round(double value, int decimals)Round to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
round
public static float round(float value, int decimals)Round to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
ceil
public static double ceil(double value, int decimals)Round up to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
ceil
public static float ceil(float value, int decimals)Round up to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
floor
public static double floor(double value, int decimals)Round down to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
floor
public static float floor(float value, int decimals)Round down to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
rint
public static double rint(double value, int decimals)Round (to nearest integer) to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
rint
public static float rint(float value, int decimals)Round (to nearest integer) to specific number of digits after decimal point.- Parameters:
value- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
apply
public static double apply(RoundingType type, double value, int decimals)
Apply the specified rounding type.- Parameters:
type- the rounding typevalue- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
apply
public static float apply(RoundingType type, float value, int decimals)
Apply the specified rounding type.- Parameters:
type- the rounding typevalue- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value
-
fixDecimals
protected static String fixDecimals(String s, int decimals)
Fixes rounding issues, ensuring that only the specified number of decimals get returned.- Parameters:
s- the string to processdecimals- the number of decimals to ensure- Returns:
- the processed string
-
toString
public static String toString(RoundingType type, double value, int decimals)
Apply the specified rounding type and generates a string.- Parameters:
type- the rounding typevalue- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value as string
-
toString
public static String toString(RoundingType type, float value, int decimals)
Apply the specified rounding type and generates a string.- Parameters:
type- the rounding typevalue- the value to rounddecimals- the decimals after the decimal point to use- Returns:
- the rounded value as string
-
-