mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-17 03:00:18 +00:00
Split util classes.
This commit is contained in:
parent
98e427e831
commit
09f67c9723
103 changed files with 1245 additions and 1071 deletions
Essentials/src/com/earth2me/essentials/utils
56
Essentials/src/com/earth2me/essentials/utils/NumberUtil.java
Normal file
56
Essentials/src/com/earth2me/essentials/utils/NumberUtil.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package com.earth2me.essentials.utils;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class NumberUtil
|
||||
{
|
||||
static DecimalFormat threeDPlaces = new DecimalFormat("#,###.###");
|
||||
static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public static String shortCurrency(final BigDecimal value, final IEssentials ess)
|
||||
{
|
||||
return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value);
|
||||
}
|
||||
|
||||
public static String formatDouble(final double value)
|
||||
{
|
||||
threeDPlaces.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return threeDPlaces.format(value);
|
||||
}
|
||||
|
||||
public static String formatAsCurrency(final BigDecimal value)
|
||||
{
|
||||
currencyFormat.setRoundingMode(RoundingMode.FLOOR);
|
||||
String str = currencyFormat.format(value);
|
||||
if (str.endsWith(".00"))
|
||||
{
|
||||
str = str.substring(0, str.length() - 3);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String displayCurrency(final BigDecimal value, final IEssentials ess)
|
||||
{
|
||||
return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value));
|
||||
}
|
||||
|
||||
public static boolean isInt(final String sInt)
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt(sInt);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue