#39 Added basic implementation

This commit is contained in:
Marvin Scham
2023-05-23 02:58:10 +02:00
parent 175140451d
commit 70221d26a6
5 changed files with 304 additions and 10 deletions

View File

@@ -1,5 +1,39 @@
package de.rwu.easydrop.util;
public class FormattingUtil {
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;
/**
* Helps format a bunch of things.
*
* @since 0.1.0
*/
public final class FormattingUtil {
/**
* Private constructor to prevent unwanted instantiation.
*
* @throws UnsupportedOperationException always
*/
private FormattingUtil() throws UnsupportedOperationException {
throw new UnsupportedOperationException("This is a utility class, don't instantiate it.");
}
/**
* Formats a price to the German Euro format.
*
* @param amount price
* @return formatted price
*/
public static String formatEuro(final double amount) {
// Set up environment
Locale locale = Locale.GERMANY;
Currency currency = Currency.getInstance("EUR");
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
numberFormat.setCurrency(currency);
return numberFormat.format(amount);
}
}