aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/util
diff options
context:
space:
mode:
authorQuetz4l <aizektro@gmail.com>2024-03-24 23:02:42 +0200
committerGitHub <noreply@github.com>2024-03-24 22:02:42 +0100
commita469127b5c0423fb9e6ddb19dd4d881f4e49a609 (patch)
tree76873a7eb4fbd46dc54be4566678735f7353beb8 /src/main/java/util
parent60e4d7a1836a08be907e551b154de65c7832d165 (diff)
downloadGT5-Unofficial-a469127b5c0423fb9e6ddb19dd4d881f4e49a609.tar.gz
GT5-Unofficial-a469127b5c0423fb9e6ddb19dd4d881f4e49a609.tar.bz2
GT5-Unofficial-a469127b5c0423fb9e6ddb19dd4d881f4e49a609.zip
add info for lsc (#84)
* add info for lsc update bs and dep * add info for lsc-> change calculate function * add info for lsc-> optimization function
Diffstat (limited to 'src/main/java/util')
-rw-r--r--src/main/java/util/Util.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/util/Util.java b/src/main/java/util/Util.java
index 6a56dfa8aa..17bcf2b841 100644
--- a/src/main/java/util/Util.java
+++ b/src/main/java/util/Util.java
@@ -1,8 +1,14 @@
package util;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
@@ -12,6 +18,17 @@ import common.items.ErrorItem;
public class Util {
+ protected static final DecimalFormat percentFormatRound_6 = new DecimalFormat("0.000000%");
+ protected static final DecimalFormat percentFormatRound_2 = new DecimalFormat("0.00%");
+ protected static final BigDecimal Threshold_1 = BigDecimal.valueOf(0.01);
+ protected static DecimalFormat standardFormat;
+
+ static {
+ DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
+ dfs.setExponentSeparator("x10^");
+ standardFormat = new DecimalFormat("0.00E0", dfs);
+ }
+
public static ItemStack getStackofAmountFromOreDict(String oredictName, final int amount) {
final ArrayList<ItemStack> list = OreDictionary.getOres(oredictName);
if (!list.isEmpty()) {
@@ -48,4 +65,25 @@ public class Util {
}
return ret;
}
+
+ /* If the number is less than 1, we round by the 6, otherwise to 2 */
+ public static String toPercentageFrom(BigInteger value, BigInteger maxValue) {
+ BigDecimal result = new BigDecimal(value).setScale(6, RoundingMode.HALF_UP)
+ .divide(new BigDecimal(maxValue), RoundingMode.HALF_UP);
+ if (result.compareTo(Threshold_1) < 0) {
+ return percentFormatRound_6.format(result);
+ } else {
+ return percentFormatRound_2.format(result);
+ }
+ }
+
+ /* Get a string like this: 4.56*10^25 */
+ public static String toStandardForm(BigInteger number) {
+ if (BigInteger.ZERO.equals(number)) {
+ return "0";
+ }
+
+ return standardFormat.format(number);
+ }
+
}