Skip to content

Commit

Permalink
Fix number handling to a more D2 styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 23, 2018
1 parent 0127053 commit e6c01a9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/net/aufdemrand/denizencore/objects/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,38 @@ public Element(boolean bool) {
}

public Element(int integer) {
this.prefix = "integer";
this.prefix = "number";
this.element = String.valueOf(integer);
}

public Element(byte byt) {
this.prefix = "byte";
this.prefix = "number";
this.element = String.valueOf(byt);
}

public Element(short shrt) {
this.prefix = "short";
this.prefix = "number";
this.element = String.valueOf(shrt);
}

public Element(long lng) {
this.prefix = "long";
this.prefix = "number";
this.element = String.valueOf(lng);
}

public Element(BigDecimal bdl) {
this.prefix = "decimal";
this.element = CoreUtilities.bigDecToString(bdl);
}

public Element(double dbl) {
this.prefix = "double";
this.element = String.valueOf(dbl);
this.prefix = "decimal";
this.element = CoreUtilities.doubleToString(dbl);
}

public Element(float flt) {
this.prefix = "float";
this.element = String.valueOf(flt);
this.prefix = "decimal";
this.element = CoreUtilities.doubleToString(flt);
}

public Element(String prefix, String string) {
Expand Down Expand Up @@ -1676,7 +1681,7 @@ public String run(Attribute attribute, dObject object) {
return null;
}
try {
return new Element(ele.asBigDecimal().add(ele.getBD(attribute.getContext(1))).toString())
return new Element(ele.asBigDecimal().add(ele.getBD(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
}
catch (Throwable e) {
Expand Down Expand Up @@ -1706,7 +1711,7 @@ public String run(Attribute attribute, dObject object) {
return null;
}
try {
return new Element(ele.asBigDecimal().divide(ele.getBD(attribute.getContext(1))).toString())
return new Element(ele.asBigDecimal().divide(ele.getBD(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
}
catch (Throwable e) {
Expand Down Expand Up @@ -1760,7 +1765,7 @@ public String run(Attribute attribute, dObject object) {
return null;
}
try {
return new Element(ele.asBigDecimal().multiply(ele.getBD(attribute.getContext(1))).toString())
return new Element(ele.asBigDecimal().multiply(ele.getBD(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
}
catch (Throwable e) {
Expand Down Expand Up @@ -1790,7 +1795,7 @@ public String run(Attribute attribute, dObject object) {
return null;
}
try {
return new Element(ele.asBigDecimal().subtract(ele.getBD(attribute.getContext(1))).toString())
return new Element(ele.asBigDecimal().subtract(ele.getBD(attribute.getContext(1))))
.getAttribute(attribute.fulfill(1));
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.io.FilenameFilter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -31,6 +32,22 @@ public boolean accept(File file, String fileName) {
};
}

public static String bigDecToString(BigDecimal input) {
String temp = input.toString();
if (temp.endsWith(".0")) {
return temp.substring(0, temp.length() - 2);
}
return temp;
}

public static String doubleToString(double input) {
String temp = String.valueOf(input);
if (temp.endsWith(".0")) {
return temp.substring(0, temp.length() - 2);
}
return temp;
}

/**
* Lists all files in the given directory.
*
Expand Down

0 comments on commit e6c01a9

Please sign in to comment.