Skip to content

Commit

Permalink
Adding methods for reform rational numbers to a String
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneFuture committed Dec 12, 2023
1 parent 4a421c5 commit 50aa553
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/main/java/de/redstoneworld/redutilities/misc/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,51 @@ public static float getRationalNumberValue(String cmdInput) {
// convert the string to a float number
return Float.parseFloat(cmdInput);
}

/**
* This method outputs the rational number as a string.
* The decimal separator remains at the point (".") .
*
* @param floatValue the rational number
* @return (String) the formatted string.
*/
public static String getRationalNumberMsg(float floatValue) {
return getRationalNumberMsg(floatValue, ".");
}

/**
* This method outputs the rational number as a string.
* The decimal separator remains at the point (".") .
*
* @param doubleValue the rational number
* @return (String) the formatted string.
*/
public static String getRationalNumberMsg(Double doubleValue) {
return getRationalNumberMsg(doubleValue, ".");
}

/**
* This method outputs the rational number as a string.
* The decimal separator can also be specified.
*
* @param floatValue the rational number
* @param decimalSeparator the decimal separator
* @return (String) the formatted string.
*/
public static String getRationalNumberMsg(float floatValue, String decimalSeparator) {
return String.valueOf(floatValue).replace(".", decimalSeparator);
}

/**
* This method outputs the rational number as a string.
* The decimal separator can also be specified.
*
* @param doubleValue the rational number
* @param decimalSeparator the decimal separator
* @return (String) the formatted string.
*/
public static String getRationalNumberMsg(Double doubleValue, String decimalSeparator) {
return String.valueOf(doubleValue).replace(".", decimalSeparator);
}

}

0 comments on commit 50aa553

Please sign in to comment.