mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-08-10 17:55:44 +00:00
Merge pull request #2872 from JoelBenReneHecht/Numitron_OC_Enhancements
Numitron Enhancements for OpenComputers
This commit is contained in:
commit
319519ad64
@ -21,7 +21,7 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
|
|||||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rbmk_numitron.png");
|
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_rbmk_numitron.png");
|
||||||
public TileEntityRBMKNumitron display;
|
public TileEntityRBMKNumitron display;
|
||||||
protected int xSize = 256;
|
protected int xSize = 256;
|
||||||
protected int ySize = 114;
|
protected int ySize = 150;
|
||||||
protected int guiLeft;
|
protected int guiLeft;
|
||||||
protected int guiTop;
|
protected int guiTop;
|
||||||
|
|
||||||
@ -29,6 +29,8 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
|
|||||||
protected GuiTextField[] rtty = new GuiTextField[2];
|
protected GuiTextField[] rtty = new GuiTextField[2];
|
||||||
protected boolean[] active = new boolean[2];
|
protected boolean[] active = new boolean[2];
|
||||||
protected boolean[] polling = 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) {
|
public GUIScreenRBMKDisplay(TileEntityRBMKNumitron display) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
@ -46,13 +48,15 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
|
|||||||
int oY = 4;
|
int oY = 4;
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
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);
|
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);
|
GUIScreenRBMKKeyPad.setupTextFieldStandard(rtty[i], 10, display.displays[i].rtty);
|
||||||
|
|
||||||
active[i] = display.displays[i].active;
|
active[i] = display.displays[i].active;
|
||||||
polling[i] = display.displays[i].polling;
|
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);
|
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
if(this.active[i]) drawTexturedModalRect(guiLeft + 111, guiTop + i * 36 + 54, 18, 114, 16, 16);
|
if(this.active[i]) drawTexturedModalRect(guiLeft + 124, guiTop + i * 54 + 54, 18, 150, 16, 16);
|
||||||
if(this.polling[i]) drawTexturedModalRect(guiLeft + 128, guiTop + i * 36 + 53, 0, 114, 18, 18);
|
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++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
@ -91,17 +97,29 @@ public class GUIScreenRBMKDisplay extends GuiScreen {
|
|||||||
super.mouseClicked(x, y, b);
|
super.mouseClicked(x, y, b);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
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];
|
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)));
|
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.active[i] ? 0.25F : 0F)));
|
||||||
return;
|
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];
|
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)));
|
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F + (this.polling[i] ? 0.25F : 0F)));
|
||||||
return;
|
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) {
|
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();
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
byte active = 0;
|
byte active = 0;
|
||||||
byte polling = 0;
|
byte polling = 0;
|
||||||
|
byte shorten_number = 0;
|
||||||
|
byte leading_zeroes = 0;
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
if(this.active[i]) active |= 1 << i;
|
if(this.active[i]) active |= 1 << i;
|
||||||
if(this.polling[i]) polling |= 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("active", active);
|
||||||
data.setByte("polling", polling);
|
data.setByte("polling", polling);
|
||||||
|
data.setByte("shorten_number", shorten_number);
|
||||||
|
data.setByte("leading_zeroes", leading_zeroes);
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
data.setString("label" + i, this.label[i].getText());
|
data.setString("label" + i, this.label[i].getText());
|
||||||
|
|||||||
@ -55,16 +55,47 @@ public class RenderRBMKNumitron extends TileEntitySpecialRenderer {
|
|||||||
double h = 13D / scale;
|
double h = 13D / scale;
|
||||||
double yOffset = 0.5625D;
|
double yOffset = 0.5625D;
|
||||||
|
|
||||||
String value = BobMathUtil.getShortNumber(unit.value);
|
String value = "";
|
||||||
while(value.length() < 7) value = "0" + 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;
|
Tessellator tess = Tessellator.instance;
|
||||||
tess.startDrawingQuads();
|
tess.startDrawingQuads();
|
||||||
for(int j = 0; j < 7; j++) {
|
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;
|
double zOffset = (j - 3) * 0.1D;
|
||||||
char c = value.charAt(j);
|
char c = value.charAt(j);
|
||||||
double u = -1;
|
double u = -1;
|
||||||
double v = 0;
|
double v = 0;
|
||||||
|
if(c == ' ') continue;
|
||||||
if(c == '.') {u = 0.9; v = 0.5;}
|
if(c == '.') {u = 0.9; v = 0.5;}
|
||||||
if(c == '-') {u = 0.8; v = 0.5;}
|
if(c == '-') {u = 0.8; v = 0.5;}
|
||||||
else if(c == 'k') {u = 0.0; 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 == 'T') {u = 0.3; v = 0.5;}
|
||||||
else if(c == 'P') {u = 0.4; 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
|
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(charVal >= 0 && charVal <= 9) {u = 0.1 * charVal; v = 0.0;}
|
||||||
if(u == -1) {u = 0.8; v = 0.5;}
|
if(u == -1) {u = 0.8; v = 0.5;}
|
||||||
tess.setNormal(0F, 1F, 0F);
|
tess.setNormal(0F, 1F, 0F);
|
||||||
|
|||||||
@ -88,9 +88,18 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
public long value;
|
public long value;
|
||||||
/** Whether this display is visible on the panel */
|
/** Whether this display is visible on the panel */
|
||||||
public boolean active;
|
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) {
|
public DisplayUnit(int initialIndex) {
|
||||||
label = "Display " + (initialIndex + 1);
|
label = "Display " + (initialIndex + 1);
|
||||||
|
active_digits = 0b01111111;
|
||||||
|
shorten_number = true;
|
||||||
|
leading_zeroes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
@ -113,6 +122,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void serialize(ByteBuf buf) {
|
public void serialize(ByteBuf buf) {
|
||||||
|
buf.writeBoolean(shorten_number);
|
||||||
|
buf.writeLong(active_digits);
|
||||||
|
buf.writeBoolean(leading_zeroes);
|
||||||
buf.writeBoolean(active);
|
buf.writeBoolean(active);
|
||||||
buf.writeBoolean(polling);
|
buf.writeBoolean(polling);
|
||||||
BufferUtil.writeString(buf, label);
|
BufferUtil.writeString(buf, label);
|
||||||
@ -121,6 +133,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deserialize(ByteBuf buf) {
|
public void deserialize(ByteBuf buf) {
|
||||||
|
shorten_number = buf.readBoolean();
|
||||||
|
active_digits = buf.readLong();
|
||||||
|
leading_zeroes = buf.readBoolean();
|
||||||
active = buf.readBoolean();
|
active = buf.readBoolean();
|
||||||
polling = buf.readBoolean();
|
polling = buf.readBoolean();
|
||||||
label = BufferUtil.readString(buf);
|
label = BufferUtil.readString(buf);
|
||||||
@ -129,6 +144,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt, int index) {
|
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.active = nbt.getBoolean("active" + index);
|
||||||
this.polling = nbt.getBoolean("polling" + index);
|
this.polling = nbt.getBoolean("polling" + index);
|
||||||
this.label = nbt.getString("label" + 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) {
|
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("active" + index, active);
|
||||||
nbt.setBoolean("polling" + index, polling);
|
nbt.setBoolean("polling" + index, polling);
|
||||||
nbt.setString("label" + index, label);
|
nbt.setString("label" + index, label);
|
||||||
@ -158,9 +179,13 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
|
|
||||||
int active = data.getByte("active");
|
int active = data.getByte("active");
|
||||||
int polling = data.getByte("polling");
|
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++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
this.displays[i].active = (active & (1 << i)) != 0;
|
this.displays[i].active = (active & (1 << i)) != 0;
|
||||||
this.displays[i].polling = (polling & (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++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
@ -183,6 +208,9 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
int idx = args.checkInteger(0) - 1;
|
int idx = args.checkInteger(0) - 1;
|
||||||
if(idx < 0 || idx >= 2) return new Object[] {null, "Invalid index (1-2)"};
|
if(idx < 0 || idx >= 2) return new Object[] {null, "Invalid index (1-2)"};
|
||||||
java.util.LinkedHashMap<String, Object> map = new java.util.LinkedHashMap<>();
|
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("active", displays[idx].active);
|
||||||
map.put("polling", displays[idx].polling);
|
map.put("polling", displays[idx].polling);
|
||||||
map.put("label", displays[idx].label);
|
map.put("label", displays[idx].label);
|
||||||
@ -241,4 +269,36 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
|
|||||||
markDirty();
|
markDirty();
|
||||||
return new Object[] {true};
|
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};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,39 +193,45 @@ public class BobMathUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getShortNumber(long l) {
|
public static String getShortNumber(long l) {
|
||||||
|
double res;
|
||||||
|
String magnitude_letter = "";
|
||||||
|
|
||||||
if(l >= Math.pow(10, 18)) {
|
if(Math.abs(l) >= Math.pow(10, 18)) {
|
||||||
double res = l / Math.pow(10, 18);
|
res = l / Math.pow(10, 18);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "E";
|
||||||
return res + "E";
|
|
||||||
}
|
}
|
||||||
if(l >= Math.pow(10, 15)) {
|
else if(Math.abs(l) >= Math.pow(10, 15)) {
|
||||||
double res = l / Math.pow(10, 15);
|
res = l / Math.pow(10, 15);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "P";
|
||||||
return res + "P";
|
|
||||||
}
|
}
|
||||||
if(l >= Math.pow(10, 12)) {
|
else if(Math.abs(l) >= Math.pow(10, 12)) {
|
||||||
double res = l / Math.pow(10, 12);
|
res = l / Math.pow(10, 12);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "T";
|
||||||
return res + "T";
|
|
||||||
}
|
}
|
||||||
if(l >= Math.pow(10, 9)) {
|
else if(Math.abs(l) >= Math.pow(10, 9)) {
|
||||||
double res = l / Math.pow(10, 9);
|
res = l / Math.pow(10, 9);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "G";
|
||||||
return res + "G";
|
|
||||||
}
|
}
|
||||||
if(l >= Math.pow(10, 6)) {
|
else if(Math.abs(l) >= Math.pow(10, 6)) {
|
||||||
double res = l / Math.pow(10, 6);
|
res = l / Math.pow(10, 6);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "M";
|
||||||
return res + "M";
|
|
||||||
}
|
}
|
||||||
if(l >= Math.pow(10, 3)) {
|
else if(Math.abs(l) >= Math.pow(10, 3)) {
|
||||||
double res = l / Math.pow(10, 3);
|
res = l / Math.pow(10, 3);
|
||||||
res = Math.round(res * 100.0) / 100.0;
|
magnitude_letter = "k";
|
||||||
return res + "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 |
Loading…
x
Reference in New Issue
Block a user