Compare commits

...

23 Commits

Author SHA1 Message Date
HbmMods
319519ad64
Merge pull request #2872 from JoelBenReneHecht/Numitron_OC_Enhancements
Numitron Enhancements for OpenComputers
2026-05-03 11:14:33 +02:00
HbmMods
6f52fb8e37
Merge pull request #2878 from DTK-MrRaccoon/ror
More RoR
2026-05-03 11:00:25 +02:00
HbmMods
be405b43d6
Merge pull request #2881 from JoelBenReneHecht/Crane_OC_Enhancements
RBMK Crane OpenComputers: getRodInfo()
2026-05-03 10:59:41 +02:00
HbmMods
8363e651c9
Merge pull request #2882 from JoelBenReneHecht/ConsoleStorage_OC_Enhancement
RBMK Storage Column info on Console.getColumnInfo()
2026-05-03 10:59:15 +02:00
DaSH
48dd2a1e64 Shouldn't have removed the old methods as that may break other people's OC scripts 2026-05-01 22:50:17 +02:00
DaSH
8837cb51f4 minor change 2026-05-01 22:46:03 +02:00
DaSH
4b5af37d1a Storage Column now gives info about fuel if stored 2026-05-01 22:14:29 +02:00
DaSH
9830e85293 RBMK Crane get fuel info 2026-05-01 21:55:44 +02:00
DaSH
915cfc45a5 Bug fix 2026-05-01 00:26:59 +02:00
DaSH
820da70e5f Numitron GUI 2026-04-30 13:09:12 +02:00
DaSH
93a159c342 First work on Numitron GUI 2026-04-30 12:08:01 +02:00
DaSH
a3c89f6077 inverted no_leading_zeroes to leading_zeroes 2026-04-30 12:05:42 +02:00
DaSH
58ef5583b2 display mode long changed to shorten number boolean 2026-04-30 11:56:00 +02:00
DaSH
70e1f48de0 No more hexadecimal display 2026-04-30 10:36:16 +02:00
DaSH
d57a8c9dc4 Hard Exception when setting display mode or active digits with an illegal value 2026-04-30 10:24:04 +02:00
DTK-MrRaccoon
699ac52b77
Merge branch 'HbmMods:master' into ror 2026-04-30 02:00:45 +02:00
DTK-MrRaccoon
a1fcb3e2ac ror for oilburner 2026-04-30 02:00:12 +02:00
DTK-MrRaccoon
a7c337090e ror for heattex 2026-04-30 01:31:14 +02:00
DaSH
a4a6647502 comment fix 2026-04-28 12:45:33 +02:00
DaSH
3e9b104dbc OpenComputers Conventions:
-display mode id now starts at 1 as seen from OC
-range checks for setting active digits and display mode
2026-04-28 10:28:13 +02:00
DaSH
7707d9e44c Comment enhancement 2026-04-28 10:24:17 +02:00
DaSH
92c86a5719 Hexadecimal Display, Negative Number Display Fix, Active Digit Selection 2026-04-28 02:17:43 +02:00
DaSH
1b1dc6f998 Can deactivate leading zeroes 2026-04-27 23:32:45 +02:00
9 changed files with 253 additions and 37 deletions

View File

@ -21,7 +21,7 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rbmk_numitron.png");
public TileEntityRBMKNumitron display;
protected int xSize = 256;
protected int ySize = 114;
protected int ySize = 150;
protected int guiLeft;
protected int guiTop;
@ -29,6 +29,8 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
protected GuiTextField[] rtty = new GuiTextField[2];
protected boolean[] active = new boolean[2];
protected boolean[] polling = new boolean[2];
protected boolean[] shorten_number = new boolean[2];
protected boolean[] leading_zeroes = new boolean[2];
public GUIScreenRBMKDisplay(TileEntityRBMKNumitron display) {
this.display = display;
@ -46,13 +48,15 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
int oY = 4;
for(int i = 0; i < 2; i++) {
label[i] = new GuiTextField(this.fontRendererObj, guiLeft + 175 + oX, guiTop + 55 + oY + i * 36, 72 - oX * 2, 14);
label[i] = new GuiTextField(this.fontRendererObj, guiLeft + 27 + oX, guiTop + 73 + oY + i * 54, 85 - oX * 2, 14);
GUIScreenRBMKKeyPad.setupTextFieldStandard(label[i], 30, display.displays[i].label);
rtty[i] = new GuiTextField(this.fontRendererObj, guiLeft + 27 + oX, guiTop + 55 + oY + i * 36, 72 - oX * 2, 14);
rtty[i] = new GuiTextField(this.fontRendererObj, guiLeft + 27 + oX, guiTop + 55 + oY + i * 54, 85 - oX * 2, 14);
GUIScreenRBMKKeyPad.setupTextFieldStandard(rtty[i], 10, display.displays[i].rtty);
active[i] = display.displays[i].active;
polling[i] = display.displays[i].polling;
shorten_number[i] = display.displays[i].shorten_number;
leading_zeroes[i] = display.displays[i].leading_zeroes;
}
}
@ -76,8 +80,10 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
for(int i = 0; i < 2; i++) {
if(this.active[i]) drawTexturedModalRect(guiLeft + 111, guiTop + i * 36 + 54, 18, 114, 16, 16);
if(this.polling[i]) drawTexturedModalRect(guiLeft + 128, guiTop + i * 36 + 53, 0, 114, 18, 18);
if(this.active[i]) drawTexturedModalRect(guiLeft + 124, guiTop + i * 54 + 54, 18, 150, 16, 16);
if(this.polling[i]) drawTexturedModalRect(guiLeft + 159, guiTop + i * 54 + 53, 0, 150, 18, 18);
if(this.shorten_number[i]) drawTexturedModalRect(guiLeft + 195, guiTop + i * 54 + 53, 34, 150, 18, 18);
if(this.leading_zeroes[i]) drawTexturedModalRect(guiLeft + 231, guiTop + i * 54 + 53, 52, 150, 18, 18);
}
for(int i = 0; i < 2; i++) {
@ -91,17 +97,29 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
super.mouseClicked(x, y, b);
for(int i = 0; i < 2; i++) {
if(guiLeft + 111 <= x && guiLeft + 111 + 16 > x && guiTop + i * 36 + 54 < y && guiTop + i * 36 + 54 + 16 >= y) {
if(guiLeft + 124 <= x && guiLeft + 124 + 16 > x && guiTop + i * 54 + 54 < y && guiTop + i * 54 + 54 + 16 >= y) {
this.active[i] = !this.active[i];
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.active[i] ? 0.25F : 0F)));
return;
}
if(guiLeft + 128 <= x && guiLeft + 128 + 18 > x && guiTop + i * 36 + 53 < y && guiTop + i * 36 + 53 + 18 >= y) {
if(guiLeft + 159 <= x && guiLeft + 159 + 18 > x && guiTop + i * 54 + 53 < y && guiTop + i * 54 + 53 + 18 >= y) {
this.polling[i] = !this.polling[i];
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.polling[i] ? 0.25F : 0F)));
return;
}
if(guiLeft + 195 <= x && guiLeft + 195 + 18 > x && guiTop + i * 54 + 53 < y && guiTop + i * 54 + 53 + 18 >= y) {
this.shorten_number[i] = !this.shorten_number[i];
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.shorten_number[i] ? 0.25F : 0F)));
return;
}
if(guiLeft + 231 <= x && guiLeft + 231 + 18 > x && guiTop + i * 54 + 53 < y && guiTop + i * 54 + 53 + 18 >= y) {
this.leading_zeroes[i] = !this.leading_zeroes[i];
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.leading_zeroes[i] ? 0.25F : 0F)));
return;
}
}
if(guiLeft + 209 <= x && guiLeft + 209 + 18 > x && guiTop + 17 < y && guiTop + 17 + 18 >= y) {
@ -109,12 +127,18 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
NBTTagCompound data = new NBTTagCompound();
byte active = 0;
byte polling = 0;
byte shorten_number = 0;
byte leading_zeroes = 0;
for(int i = 0; i < 2; i++) {
if(this.active[i]) active |= 1 << i;
if(this.polling[i]) polling |= 1 << i;
if(this.shorten_number[i]) shorten_number |= 1 << i;
if(this.leading_zeroes[i]) leading_zeroes |= 1 << i;
}
data.setByte("active", active);
data.setByte("polling", polling);
data.setByte("shorten_number", shorten_number);
data.setByte("leading_zeroes", leading_zeroes);
for(int i = 0; i < 2; i++) {
data.setString("label" + i, this.label[i].getText());

View File

@ -55,16 +55,47 @@ public class RenderRBMKNumitron extends TileEntitySpecialRenderer {
double h = 13D / scale;
double yOffset = 0.5625D;
String value = BobMathUtil.getShortNumber(unit.value);
while(value.length() < 7) value = "0" + value;
String value = "";
if (unit.shorten_number) {
value = BobMathUtil.getShortNumber(unit.value);
} else {
// Overflow handling
if (unit.value > 9999999) {
value = "9999999";
}
// Underflow handling
else if (unit.value < -999999) {
value = "-999999";
}
else {
value = Long.toString(unit.value);
}
}
//** Fill up to 7 characters */
//** For negative numbers when zeroes are added: put the zeroes between the '-' and the number */
if ((value.length() < 7) && (value.charAt(0) == '-') && unit.leading_zeroes) {
value = value.substring(1);
while(value.length() < 6) value = "0" + value;
value = "-" + value;
} else {
String fill_char = unit.leading_zeroes?"0":" ";
while(value.length() < 7) value = fill_char + value;
}
Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
for(int j = 0; j < 7; j++) {
//** Check if this digit is active */
//** 0x40 is the bit for the left-most digit, with which this starts */
if((unit.active_digits & (0x40L>>j)) == 0) continue;
double zOffset = (j - 3) * 0.1D;
char c = value.charAt(j);
double u = -1;
double v = 0;
if(c == ' ') continue;
if(c == '.') {u = 0.9; v = 0.5;}
if(c == '-') {u = 0.8; v = 0.5;}
else if(c == 'k') {u = 0.0; v = 0.5;}
@ -73,7 +104,7 @@ public class RenderRBMKNumitron extends TileEntitySpecialRenderer {
else if(c == 'T') {u = 0.3; v = 0.5;}
else if(c == 'P') {u = 0.4; v = 0.5;}
else if(c == 'E') {u = 0.5; v = 0.5;} // i would love to say this sucks, but this is actually surprisingly easy to read and probably the most performant way of doing it
int charVal = c - '0'; // no string operations, no int parsing, no nothing, we just rawdog shit shit
int charVal = c - '0'; // no string operations, no int parsing, no nothing, we just rawdog this shit
if(charVal >= 0 && charVal <= 9) {u = 0.1 * charVal; v = 0.0;}
if(u == -1) {u = 0.8; v = 0.5;}
tess.setNormal(0F, 1F, 0F);

View File

@ -15,6 +15,7 @@ import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.fluid.IFluidStandardTransceiver;
import api.hbm.redstoneoverradio.IRORValueProvider;
import api.hbm.tile.IHeatSource;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -28,7 +29,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHeatSource, IFluidStandardTransceiver, IGUIProvider, IControlReceiver, IFluidCopiable {
public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHeatSource, IFluidStandardTransceiver, IGUIProvider, IControlReceiver, IFluidCopiable, IRORValueProvider {
public FluidTank[] tanks;
public int amountToCool = 24_000;
@ -267,4 +268,21 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe
}
if(nbt.hasKey("toCool")) amountToCool = nbt.getInteger("toCool");
}
@Override
public String[] getFunctionInfo() {
return new String[] {
PREFIX_VALUE + "hotfluid",
PREFIX_VALUE + "coldfluid",
PREFIX_VALUE + "heat"
};
}
@Override
public String provideRORValue(String name) {
if((PREFIX_VALUE + "hotfluid").equals(name)) return "" + tanks[0].getFill();
if((PREFIX_VALUE + "coldfluid").equals(name)) return "" + tanks[1].getFill();
if((PREFIX_VALUE + "heat").equals(name)) return "" + heatEnergy;
return null;
}
}

View File

@ -14,6 +14,8 @@ import com.hbm.tileentity.TileEntityMachinePolluting;
import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.fluid.IFluidStandardTransceiver;
import api.hbm.redstoneoverradio.IRORInteractive;
import api.hbm.redstoneoverradio.IRORValueProvider;
import api.hbm.tile.IHeatSource;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -24,7 +26,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
public class TileEntityHeaterOilburner extends TileEntityMachinePolluting implements IGUIProvider, IFluidStandardTransceiver, IHeatSource, IControlReceiver, IFluidCopiable {
public class TileEntityHeaterOilburner extends TileEntityMachinePolluting implements IGUIProvider, IFluidStandardTransceiver, IHeatSource, IControlReceiver, IFluidCopiable, IRORValueProvider, IRORInteractive {
public boolean isOn = false;
public FluidTank tank;
@ -234,4 +236,47 @@ public class TileEntityHeaterOilburner extends TileEntityMachinePolluting implem
if(nbt.hasKey("isOn")) isOn = nbt.getBoolean("isOn");
if(nbt.hasKey("burnRate")) setting = nbt.getInteger("burnRate");
}
@Override
public String[] getFunctionInfo() {
return new String[] {
PREFIX_VALUE + "heat",
PREFIX_VALUE + "fuel",
PREFIX_VALUE + "burnRate",
PREFIX_VALUE + "state",
PREFIX_FUNCTION + "setState" + NAME_SEPARATOR + "active",
PREFIX_FUNCTION + "setBurnRate" + NAME_SEPARATOR + "rate"
};
}
@Override
public String provideRORValue(String name) {
if((PREFIX_VALUE + "heat").equals(name)) return "" + heatEnergy;
if((PREFIX_VALUE + "fuel").equals(name)) return "" + tank.getFill();
if((PREFIX_VALUE + "burnRate").equals(name)) return "" + setting;
if((PREFIX_VALUE + "state").equals(name)) return isOn ? "1" : "0";
return null;
}
@Override
public String runRORFunction(String name, String[] params) {
if((PREFIX_FUNCTION + "setState").equals(name)) {
this.isOn = params[0].equals("1");
this.markChanged();
return null;
}
if((PREFIX_FUNCTION + "setBurnRate").equals(name)) {
try {
int rate = Integer.parseInt(params[0]);
if(rate < 1) rate = 1;
if(rate > 10) rate = 10;
this.setting = rate;
this.markChanged();
return null;
} catch (NumberFormatException e) {
return "Invalid number";
}
}
return null;
}
}

View File

@ -435,6 +435,22 @@ public class TileEntityCraneConsole extends TileEntityLoadedBase implements Simp
return new Object[] {"Crane not found"};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getRodInfo(Context context, Arguments args) {
java.util.LinkedHashMap<String, Object> map = new java.util.LinkedHashMap<>();
if(loadedItem != null && loadedItem.getItem() instanceof ItemRBMKRod) {
map.put("coreSkinTemp", ItemRBMKRod.getHullHeat(loadedItem));
map.put("coreTemp", ItemRBMKRod.getCoreHeat(loadedItem));
map.put("enrichment", ItemRBMKRod.getEnrichment(loadedItem));
map.put("xenon", ItemRBMKRod.getPoisonLevel(loadedItem));
map.put("rodName", loadedItem.getItem().getUnlocalizedName());
} else {
return new Object[] {false, "No rod loaded"};
}
return new Object[] {map};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getDepletion(Context context, Arguments args) {

View File

@ -11,6 +11,7 @@ import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.gui.GUIRBMKConsole;
import com.hbm.items.machine.ItemRBMKRod;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.tileentity.machine.rbmk.TileEntityRBMKControlManual.RBMKColor;
@ -669,6 +670,21 @@ public class TileEntityRBMKConsole extends TileEntityMachineBase implements ICon
data_table.put("cryogel", coolerChannel.getAllTanks()[0].getFill());
}
if (te instanceof TileEntityRBMKStorage){
TileEntityRBMKStorage storageChannel = (TileEntityRBMKStorage) te;
ItemStack loadedItem;
for (int k = 0; k < 12; k++) {
loadedItem = storageChannel.slots[k];
if(loadedItem != null && loadedItem.getItem() instanceof ItemRBMKRod) {
data_table.put("slot" + k + "coreSkinTemp", ItemRBMKRod.getHullHeat(loadedItem));
data_table.put("slot" + k + "coreTemp", ItemRBMKRod.getCoreHeat(loadedItem));
data_table.put("slot" + k + "enrichment", ItemRBMKRod.getEnrichment(loadedItem));
data_table.put("slot" + k + "xenon", ItemRBMKRod.getPoisonLevel(loadedItem));
data_table.put("slot" + k + "rodName", loadedItem.getItem().getUnlocalizedName());
}
}
}
return new Object[] {data_table};
}
return new Object[] {null};

View File

@ -88,9 +88,18 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
public long value;
/** Whether this display is visible on the panel */
public boolean active;
/** If leading zeros should not be added */
public boolean leading_zeroes;
/** Which digits are activated (bit mask, msb ignored) */
public long active_digits;
/** Display mode 0=normal, 1=integer */
public boolean shorten_number;
public DisplayUnit(int initialIndex) {
label = "Display " + (initialIndex + 1);
active_digits = 0b01111111;
shorten_number = true;
leading_zeroes = true;
}
public void update() {
@ -113,6 +122,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
}
public void serialize(ByteBuf buf) {
buf.writeBoolean(shorten_number);
buf.writeLong(active_digits);
buf.writeBoolean(leading_zeroes);
buf.writeBoolean(active);
buf.writeBoolean(polling);
BufferUtil.writeString(buf, label);
@ -121,6 +133,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
}
public void deserialize(ByteBuf buf) {
shorten_number = buf.readBoolean();
active_digits = buf.readLong();
leading_zeroes = buf.readBoolean();
active = buf.readBoolean();
polling = buf.readBoolean();
label = BufferUtil.readString(buf);
@ -129,6 +144,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
}
public void readFromNBT(NBTTagCompound nbt, int index) {
this.shorten_number = nbt.getBoolean("shorten_number" + index);
this.active_digits = nbt.getLong("active_digits" + index);
this.leading_zeroes = nbt.getBoolean("leading_zeroes" + index);
this.active = nbt.getBoolean("active" + index);
this.polling = nbt.getBoolean("polling" + index);
this.label = nbt.getString("label" + index);
@ -137,6 +155,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
}
public void writeToNBT(NBTTagCompound nbt, int index) {
nbt.setBoolean("shorten_number" + index, shorten_number);
nbt.setLong("active_digits" + index, active_digits);
nbt.setBoolean("leading_zeroes" + index, leading_zeroes);
nbt.setBoolean("active" + index, active);
nbt.setBoolean("polling" + index, polling);
nbt.setString("label" + index, label);
@ -158,9 +179,13 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
int active = data.getByte("active");
int polling = data.getByte("polling");
int shorten_number = data.getByte("shorten_number");
int leading_zeroes = data.getByte("leading_zeroes");
for(int i = 0; i < 2; i++) {
this.displays[i].active = (active & (1 << i)) != 0;
this.displays[i].polling = (polling & (1 << i)) != 0;
this.displays[i].shorten_number = (shorten_number & (1 << i)) != 0;
this.displays[i].leading_zeroes = (leading_zeroes & (1 << i)) != 0;
}
for(int i = 0; i < 2; i++) {
@ -183,6 +208,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {null, "Invalid index (1-2)"};
java.util.LinkedHashMap<String, Object> map = new java.util.LinkedHashMap<>();
map.put("shorten_number", displays[idx].shorten_number);
map.put("active_digits", displays[idx].active_digits);
map.put("leading_zeroes", displays[idx].leading_zeroes);
map.put("active", displays[idx].active);
map.put("polling", displays[idx].polling);
map.put("label", displays[idx].label);
@ -241,4 +269,36 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayLeadingZeroes(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].leading_zeroes = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayActiveDigits(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
long val = (long) args.checkInteger(1);
if(val < 0 || val >= 128) throw new IllegalArgumentException("Invalid value (0-127)");
displays[idx].active_digits = val;
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayShortenNumber(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].shorten_number = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
}

View File

@ -193,39 +193,45 @@ public class BobMathUtil {
}
public static String getShortNumber(long l) {
double res;
String magnitude_letter = "";
if(l >= Math.pow(10, 18)) {
double res = l / Math.pow(10, 18);
res = Math.round(res * 100.0) / 100.0;
return res + "E";
if(Math.abs(l) >= Math.pow(10, 18)) {
res = l / Math.pow(10, 18);
magnitude_letter = "E";
}
if(l >= Math.pow(10, 15)) {
double res = l / Math.pow(10, 15);
res = Math.round(res * 100.0) / 100.0;
return res + "P";
else if(Math.abs(l) >= Math.pow(10, 15)) {
res = l / Math.pow(10, 15);
magnitude_letter = "P";
}
if(l >= Math.pow(10, 12)) {
double res = l / Math.pow(10, 12);
res = Math.round(res * 100.0) / 100.0;
return res + "T";
else if(Math.abs(l) >= Math.pow(10, 12)) {
res = l / Math.pow(10, 12);
magnitude_letter = "T";
}
if(l >= Math.pow(10, 9)) {
double res = l / Math.pow(10, 9);
res = Math.round(res * 100.0) / 100.0;
return res + "G";
else if(Math.abs(l) >= Math.pow(10, 9)) {
res = l / Math.pow(10, 9);
magnitude_letter = "G";
}
if(l >= Math.pow(10, 6)) {
double res = l / Math.pow(10, 6);
res = Math.round(res * 100.0) / 100.0;
return res + "M";
else if(Math.abs(l) >= Math.pow(10, 6)) {
res = l / Math.pow(10, 6);
magnitude_letter = "M";
}
if(l >= Math.pow(10, 3)) {
double res = l / Math.pow(10, 3);
res = Math.round(res * 100.0) / 100.0;
return res + "k";
else if(Math.abs(l) >= Math.pow(10, 3)) {
res = l / Math.pow(10, 3);
magnitude_letter = "k";
}
else {
return Long.toString(l);
}
return Long.toString(l);
// Edgecase: a negative triple digit number would result in a 8 character long result so we will loose one decimal place
if (res <= -100.0) {
res = Math.round(res * 10.0) / 10.0;
} else {
res = Math.round(res * 100.0) / 100.0;
}
return res + magnitude_letter;
}
/**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB