From 50aa553c6a3b4b6d19746c8d4008b3592b142caa Mon Sep 17 00:00:00 2001 From: RedstoneFuture Date: Tue, 12 Dec 2023 13:34:58 +0100 Subject: [PATCH] Adding methods for reform rational numbers to a String --- .../redutilities/misc/Formatter.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/de/redstoneworld/redutilities/misc/Formatter.java b/src/main/java/de/redstoneworld/redutilities/misc/Formatter.java index 04db960..5949fdf 100644 --- a/src/main/java/de/redstoneworld/redutilities/misc/Formatter.java +++ b/src/main/java/de/redstoneworld/redutilities/misc/Formatter.java @@ -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); + } }